- This topic is empty.
-
AuthorPosts
-
October 20, 2013 at 3:13 pm #153563
kalmykov
ParticipantI am trying to use the PHP from Chris’ contact form https://css-tricks.com/examples/NiceSimpleContactForm2/ in my portfolio site live @ http://kovcreation.com/
I’m so frustrated after trying many different solutions I just want it to work!!!
Any help is greatly appreciated
Form HTML
`<div class="touch"> </div> <form id="contact_me_form" method="post" action="email.php"> <div class="error_contact" id="name_error">Name is Required</div> <input type="text" placeholder="Your Name (required)" id="name" class="textbox" /> <input type="text" name="email" id="email" placeholder="Your Email (required)" class="textbox email"> <div class="error_contact" id="comment_error">Message is Required</div> <textarea cols="25" rows="5" name="message" id="comment" class="textbox message" placeholder="Your Message ( Inquiry? , Freelance Work? , or Just to Say Hi...)"></textarea> <input type="image" src="img/send.png" alt="Send Message" name="submit" class="button submit_btn"> </form> </div>`
form PHP
<?php
$EmailFrom = "[email protected]";
$EmailTo = "[email protected]";
$Subject = "Nice & Simple Contact Form by CSS-Tricks";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));// validation
$validationOK=true;
if (!$validationOK) {
print "";
exit;
}// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";// send email
$success = mail($EmailTo, $Subject, $Body, "From: ");// redirect to success page
if ($success){
print "";
}
else{
print "";
}
?>October 20, 2013 at 4:01 pm #153565__
ParticipantI am trying to use the PHP from Chris’ contact form …
Any help is greatly appreciated
Help with what? Do you have a question?
offhand suggestions:
… if you have a question, describe it in detail. Tell us what you want to achieve, what you tried, and what happened (vs. what you expected to happen). “It doesn’t work” is a very useless thing to say; dumping code out onto the internet and saying “I give up, you fix it” is rude (even if you didn’t mean it to be).
… If you really did give up and just want someone else to fix it, that’s fine – but you’re no longer asking for free advice; you’re looking for someone to hire.
… sharing larger blocks of code on the discussion board doesn’t really work very well. It’s usually better to use a service like pastebin or make a gist on github.
October 21, 2013 at 2:15 pm #153631kalmykov
ParticipantI feel my post was clear. The contact form isn’t working. I want it to work. The code I posted is the code I’m using to try and make it work. I posted to see if someone could see an error in it. If you don’t know whats wrong thats fine but don’t go trolling on the forums wasting people’s time, THATS rude.
October 21, 2013 at 3:57 pm #153639__
ParticipantIt is not my intent to waste your time, nor to be rude, nor to argue about those points. I am asking what problem you are trying to solve. The reason “it doesn’t work” is not helpful is because that is already a “given” – if it did work, you wouldn’t be asking in the first place.
To explain why “not working” is not clear: How do you mean? What is the result? Are you getting blank page or other errors (and are you checking for errors)? Are you getting a success message but no email? Are you getting a blank (or garbled) email? Is the form not displaying correctly? Is it telling you there are validation errors, but there shouldn’t be? There is no way to determine any of this by looking at your code dump.
As I also mentioned, it is difficult to even check for basic errors because of how your code is displayed in the comment. (The only obvious issue there would be the empty
From:
header in your email; but that doesn’t mean it’s your main problem, or even necessarily a problem at all.) Making a gist or posting on pastebin (or {your favorite service} ) would make that practical.I am perfectly willing (eager, in fact) to help people out with their problems. That’s why I frequent this forum. If you cannot “help yourself” and accept helpful advice and participate in finding answers to your question, then I will let you alone.
October 21, 2013 at 5:16 pm #153643Alen
ParticipantIt’s always a good idea to use paste bin or whatever to showcase your code. This forum likes to chew up code when posted like that… for short snippets it’s fine if you use the Block Code! button right above the comment form.
For long form, like you posted, requires some sort of service to help us, help you.
One thing I notices is this:
In your form you have this
name="email"
but in your PHP code you’re referring to it as$_POST['Email']
. Notice the capitalE
should be lowercase.trolling on the forums wasting people’s time
Not sure why you’re so confrontational. We’re trying to help you. We could as easily ignore your request.
In fact YOU are wasting OUR time by not explaining your issue in greater detail. We are not mind readers and looking at the code you posted, we can not identify the issue.
PS. @traq is one of the members on this forum always trying to help. So the trolling statement was bit rude. And I have to give props to @traq for maintaining his cool and still trying to help you.
October 22, 2013 at 3:28 pm #153745kalmykov
ParticipantI’m new to this whole forum thing. I’m usually able to figure things out on my own but this PHP language has me stumped. I’m not trying to be confrontational I’m just trying to get some constructive help.
I’m barely a novice with PHP so I don’t know how to validate the form or trouble shoot it in anyway. The most specific I can be is that only the javascript works now upon hitting the submit button(it didn’t before I I fixed the capitalization issue and added the name attribute). No information is sent to my email whatsoever.
I’ve never used pastebin or gist on github, so apologies if this gist isn’t in the most optimal format
My biggest concern is getting the form to actually send the data inputed to my email.
October 22, 2013 at 4:21 pm #153750Alen
ParticipantAre you working locally? or Live (server)?
October 22, 2013 at 4:38 pm #153755kalmykov
ParticipantI’m working Live. I have WAMP running on my machine but it’s my understanding that the PHP script will execute but not actually send if you run it locally.
October 22, 2013 at 5:10 pm #153756__
ParticipantI’m new to this whole forum thing.
No problem. Keep in mind that it is very difficult to tell what mood people are in just by reading their comments, so it’s very easy to jump to the conclusion that they’re being mean. Of course, this effect is amplified if you’re already upset/frustrated. It’s best to imagine that they meant what they wrote in the best possible way (even if you’re sure that they didn’t).
At the top of your PHP script, add the following:
error_reporting( -1 ); ini_set( 'display_errors',1 );
…then see if you get any error messages.
I’ve never used pastebin or gist on github, so apologies if this gist isn’t in the most optimal format
It’s great. So, next suggestion is to add some output after your call to
mail()
. Right now, you just have<meta>
redirects*, so (since those pages may or may not be set up at this point) you may not get a good indication if it is successful or not. Something likeif ($success){ print "success"; } else{ print "failure"; }
is better for testing.
* actually, there is no reason to use
<meta>
redirects at all. PHP has aheader
function that can do an actual http redirect, which will always be more reliable.The most specific I can be is that only the javascript works now upon hitting the submit button(it didn’t before I I fixed the capitalization issue and added the name attribute).
Try removing the javascript for the time being. It may be preventing you from seeing what the PHP is doing (in fact, it may be preventing the PHP from doing anything in the first place).
I have WAMP running on my machine but it’s my understanding that the PHP script will execute but not actually send if you run it locally.
It will, if you have a mail server set up to listen to PHP. It’s just that most people don’t.
mail
doesn’t actually send email; it just looks for a mail server that it can submit the email message to. (It has no idea what happens after that.) If it doesn’t find one, “oh, well.”October 22, 2013 at 6:51 pm #153760kalmykov
ParticipantThanks for all the feedback. Here is my quest thus far:
I took off all the java script and added
error_reporting( -1 ); ini_set( 'display_errors',1 );
to the top of my PHP.
I got a white page with this text upon submitting.
Not Found
The requested URL /bin/contactthanks.php was not found on this server.Additionally, a 404 Not Found error was encountered while trying to use an > > ErrorDocument to handle the request.
Then I used you method for testing instead
if ($success){ print "success"; } else{ print "failure"; }
and i got a white page that just said “success”. I got all happy and rushed over to my inbox but nothing :(
I tried all of this while it was live on the server b/c I don’t know how to set up a mail server.
October 22, 2013 at 7:08 pm #153761__
Participantand i got a white page that just said “success”. I got all happy and rushed over to my inbox but nothing :(
Alright, good. Let’s look at how you’re sending your email. This time, instead of printing “success”, print this:
if($success){ print "EmailTo: $EmailTo<br>". "Subject: $Subject<br>". "Body: $Body<br>". "From: $emailFrom"; }
That way, we’ll be able to see what values you are actually using in your call to
mail
.But wait
Before you do that, try adding
crlf
after your “From” header (it’s required):// no! // mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // yes! mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>\r\n");
October 22, 2013 at 7:19 pm #153763Alen
Participant404 error is Not Found. So your
/bin/contactthanks.php
does not exist, or you have linked to it wrong. Where is the form relative to the page you’re submitting to?Also,
$success
thing doesn’t send anything, it’s just for testing. Addition by subtraction. You’re limiting the number of thing that can go wrong.- test if form is passing values first
- integrate validation
- format email
- send email
Your process is failing at number 1. Get that working first.
You should be using something like:
$name = trim(stripslashes($_POST['name'])); var_dump($name); // should print the value of Name
Var Dump is a test to see what data is being passed.
-Alen
October 22, 2013 at 7:22 pm #153766kalmykov
ParticipantThank you again for you help in this.
I change success to
if($success){ print "EmailTo: $EmailTo<br>". "Subject: $Subject<br>". "Body: $Body<br>". "From: $emailFrom"; }
and i get a white page that says:
Notice: Undefined variable: Body in >/home/admin/public_html/bin/phpmailer.php on line 18
Notice: Undefined variable: emailFrom in >/home/admin/public_html/bin/phpmailer.php on line 48
EmailTo: [email protected]
Subject: Nice & Simple Contact Form by CSS-Tricks
Body: Name: Michael Anthony Kalmykov Email: [email protected] Message: >Test message
From:I’m not sure what
crlf
does or where to put it. Is it supposed to go in the html where the form starts?<form id="contact_me_form" method="post" action="email.php">
or somewhere in the PHP?
October 22, 2013 at 7:31 pm #153767kalmykov
Participanttest if form is passing values first
integrate validation
format email
send emailThanks Alen that’s super helpful. I just dove into this thing blindly w/out any structure or process at all. It’s crazy how little info is out there on this. I thought it’d be a common thing w/ plenty of resources but it’s not the case o.0
I don’t actually want any other pages to open up upon submitting just for the bubble to pop up saying thanks, which is currently working on this form, so I’ve replaced
if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; }
with
if($success){ print "EmailTo: $EmailTo<br>". "Subject: $Subject<br>". "Body: $Body<br>". "From: $emailFrom"; } else{ print "failure"; }
for testing purposes
October 22, 2013 at 7:38 pm #153768kalmykov
ParticipantHaha I can be such an idiot.
Nevermind about the
mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>\r\n");
I put it where it’s supposed to be and now what I get is
Notice: Undefined variable: success in >/home/admin/public_html/bin/phpmailer.php on line 39
failure -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.