bassman19 Posted February 14, 2011 Share Posted February 14, 2011 I'm making a contact form using PHP, I've got the look of the form done and I'm very happy with the look - but the actual email bit is a bit challenging. I'm using the code from a contact form on css-tricks.com, and the script does send emails... and I receive them but the emails are completely blank apart from the 'name: email: message:' stuff and the subject. What am I doing wrong? Here is the code I am using: contact.html <form method="post" action="contactengine.php" id="commentForm"> <div class="form"> <p><input type="text" name="fullName" id="firstName" class="required" title="Full name" /></p> <p><input type="text" name="emailAddress" id="emailAddress" class="required" title="Email Address" /></p> <p><textarea type="text" name="message" id="message" class="required" title="Message"></textarea></p> </div> <p><input type="submit" name="submit" value="Submit" class="submit-button" title="Send" /></p> </form> contactengine.php $EmailFrom = "enquiries@aplinnovations.co.uk"; $EmailTo = "info@aplinnovations.co.uk"; $Subject = "Contact Form Submission"; $fullName = Trim(stripslashes($_POST['Name'])); $emailAddress = Trim(stripslashes($_POST['Email'])); $message = Trim(stripslashes($_POST['Message'])); $Body = ""; $Body .= "Name: "; $Body .= $fullName; $Body .= "\n"; $Body .= "Email: "; $Body .= $emailAddress; $Body .= "\n"; $Body .= "Message: "; $Body .= $message; $Body .= "\n"; $success = mail($EmailTo, $Subject, $Body, "From: $emailAddress"); I really have no idea how to code in PHP, I know I'm a newbie and I'm sure this is a really dumb question... but please help! Thanks Quote Link to comment Share on other sites More sharing options...
coupe-r Posted February 14, 2011 Share Posted February 14, 2011 Make $success = mail($EmailTo, $Subject, $Body, "From: $emailAddress"); This mail($EmailTo, $Subject, $Body, "From: $emailAddress"); And see what happends Quote Link to comment Share on other sites More sharing options...
bassman19 Posted February 14, 2011 Author Share Posted February 14, 2011 Thanks for the quick reply, but the $success is there for a reason, it leads to this: if ($success){ echo "<script>alert(\"The message was sent successfully!\");</script>"; print "<meta http-equiv=\"refresh\" content=\"0;URL=contact.html\">"; } else{ echo "<script>alert(\"There was an error sending the message. Please try again.\");</script>"; print "<meta http-equiv=\"refresh\" content=\"0;URL=contact.html\">"; } It does send the email, but only with: Name: Email: Message: :/ Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 14, 2011 Share Posted February 14, 2011 At the top, do print_r($_POST) and see if it shows what you expect. Hint: It won't. Quote Link to comment Share on other sites More sharing options...
coupe-r Posted February 14, 2011 Share Posted February 14, 2011 Good catch. In your form, you have <p><input type="text" name="fullName" id="firstName" class="required" title="Full name" /></p> <p><input type="text" name="emailAddress" id="emailAddress" class="required" title="Email Address" /></p> <p><textarea type="text" name="message" id="message" class="required" title="Message"></textarea></p> In your PHP, you need to use the same $_POST vars as the name of the input. Example $fullName = Trim(stripslashes($_POST['fullName'])); Quote Link to comment Share on other sites More sharing options...
bassman19 Posted February 14, 2011 Author Share Posted February 14, 2011 coupe-r: Thank you very much kind sir! it worked! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.