March 23, 201016 yr Hi, I wanted to just thank everyone that has helped me on this board. but i have one more issue. i have a decent contact form php set up, and when i submit, it says that it's sent but i don't receive the email. (i have checked that the email address is correct and i have waited for hours for it to come so it shouldn't be those reasons. could someone please let me know if something is wrong in the code? thanks!!! (by the way i am using a template in this one, that is why it's in table format. rest assured that i don't make table websites, i actually hate them). oh and this is the website it's on www.myfashionoutlet.co.uk/contact.html - feel free to use the contact form as much as you like if you are messing around to try it. (the required fields aren't actually required so don't worry about that.) would the fact that i have fields there which aren't utilised in my form.php be causing a problem?!?! ok i am going to shut up now. thank you! <form method="post" action="form.php" id="contactform"> <table width="100%" border="0" cellpadding="0" align="center" cellspacing="0"> <tr> <td><table width="100%" border="0" cellpadding="4" cellspacing="1"> <tr> <td width="23%" align="Right"><b>Your Name: <span class="style1">*</span></b></td> <td width="77%"><input type="text" name="name" style="width: 50%;"> </td> </tr> <td align="Right"><b>E-mail Address: <span class="style1">*</span></b></td> <td><input type="text" name="email" style="width: 50%;"></td> </tr> <tr> <td align="Right"><b>Home Address: *</b></td> <td><input type="text" name="website2" style="width: 50%;"></td> </tr> <tr> <td align="Right"><b>Post Code:*</b></td> <td><input type="text" name="website2" style="width: 50%;"></td> </tr> <tr> <td align="Right"><b>Telephone:*</b></td> <td><input type="text" name="website2" style="width: 50%;"></td> </tr> <tr> <td colspan="2" align="center"> <table width="369" border="0" cellpadding="0" cellspacing="6"> <tr> <td width="369"><font size="1"><b> Questions: <span class="style1">* </span></b></font></td> </tr> <tr> <td><textarea name="message" rows="8" style="width: 94%;" wrap="VIRTUAL"></textarea></td> </tr> </table> <input type="submit" name="submit" value="Submit Form"></td> </tr> </table></td> </tr> </table> </form> and here is my form.php <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','message'); $required = array('name','email','message'); $your_email = "nlgdavies@gmail.com"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' ) { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?> If anyone could help me on this i would be sooo grateful and i will love you forever!
March 23, 201016 yr try changeing this line if(@mail($your_email,$email_subject,$email_content)) to if($mail = mail($your_email,$email_subject,$email_content,"From: <youremail@yourdomain.com>"))
March 23, 201016 yr Author Hi! Thanks for helping me. unfortunately that hasn't worked. do you think the subject part may be responsible for any problems? like here... foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' ) { as there is no subject field in my html? that's all i can think of as i am a noob with php! thanks.
March 23, 201016 yr Hi! Thanks for helping me. unfortunately that hasn't worked. do you think the subject part may be responsible for any problems? like here... foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' ) { as there is no subject field in my html? that's all i can think of as i am a noob with php! thanks. Yea try removing that or check your spam folder see if its going there
March 23, 201016 yr Author oh sweet dude! they were going to by spam folder!! thank you so much for your help man. i am really grateful for your advice. thanks again!
March 23, 201016 yr Author actually there is one more thing i wanted to know and then i promise i will leave you alone! i am assuming that the php form looks for each value in the html form like <input type="text" name="email"> and shows the response in the resulting email when it's submitted. so in the html you have <input type="text" name="email"> in the form.php you have $values = array ('name','email','message'); so when you recieve the email you get "email: your@email.com" based on that logic i wanted to capture all the fields in the html and have them sent to my email. so i added $values = array ('name','email','address','postcode','tel','message'); and i hoped that it would find name="home" etc.. and display them in the email but it's not working! please could you explain to me how i can get all my fields to show in the email after submitting the form! below is the code for my contact.html and form.php THANK YOU SO MUCH FOR HELPING ME!!! contact.html <form method="post" action="form.php" id="contactform"> <table width="100%" border="0" cellpadding="0" align="center" cellspacing="0"> <tr> <td><table width="100%" border="0" cellpadding="4" cellspacing="1"> <tr> <td width="23%" align="Right"><b>Your Name: <span class="style1">*</span></b></td> <td width="77%"><input type="text" name="name" style="width: 50%;"> </td> </tr> <td align="Right"><b>E-mail Address: <span class="style1">*</span></b></td> <td><input type="text" name="email" style="width: 50%;"></td> </tr> <tr> <td align="Right"><b>Home Address: *</b></td> <td><input type="text" name="address" style="width: 50%;"></td> </tr> <tr> <td align="Right"><b>Post Code:*</b></td> <td><input type="text" name="postcode" style="width: 50%;"></td> </tr> <tr> <td align="Right"><b>Telephone:*</b></td> <td><input type="text" name="tel" style="width: 50%;"></td> </tr> <tr> <td colspan="2" align="center"> <table width="369" border="0" cellpadding="0" cellspacing="6"> <tr> <td width="369"><font size="1"><b> Questions: <span class="style1">* </span></b></font></td> </tr> <tr> <td><textarea name="message" rows="8" style="width: 94%;" wrap="VIRTUAL"></textarea></td> </tr> </table> <input type="submit" name="submit" value="Submit Form"></td> </tr> </table></td> </tr> </table> </form> form.php <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','address','postcode','tel','message'); $required = array('name','email','message'); $your_email = "nlgdavies@gmail.com"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' ) { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?>
March 23, 201016 yr Yea sure bro just do a variable for each field of ur form. like for a email and name field you would do $name = (isset($_POST['name'])) ? $_POST['name'] : FALSE; $email = (isset($_POST['email'])) ? $_POST['email'] : FALSE; And then in your message that you send to your email you would do this $email_content = "Name: ".$name.""; $email_content .= "Email: ".$email.""; Hope this helped if it did +1 me if you like cheers
March 23, 201016 yr Author hey, Yeah i just gave you a plus one on all of your posts on this topic as you have been really helpful. i'm sorry to be a pain in the ass but i am having trouble putting what you said into practice. because of all the $value array my head is spinning and i can't work it out... i tried doing this... <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $name = (isset($_POST['name'])) ? $_POST['name'] : FALSE; $email = (isset($_POST['email'])) ? $_POST['email'] : FALSE; $required = array('name','email','message'); $your_email = "nlgdavies@gmail.com"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' ) { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content = "Name: ".$name.""; $email_content .= "Email: ".$email."";"\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?> I think i messed it up. now it just sends an email saying "message:". php is so unforgiving, i have no idea what's going on!
March 23, 201016 yr hey, Yeah i just gave you a plus one on all of your posts on this topic as you have been really helpful. i'm sorry to be a pain in the ass but i am having trouble putting what you said into practice. because of all the $value array my head is spinning and i can't work it out... i tried doing this... <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $name = (isset($_POST['name'])) ? $_POST['name'] : FALSE; $email = (isset($_POST['email'])) ? $_POST['email'] : FALSE; $required = array('name','email','message'); $your_email = "nlgdavies@gmail.com"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "new message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' ) { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content = "Name: ".$name.""; $email_content .= "Email: ".$email."";"\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?> I think i messed it up. now it just sends an email saying "message:". php is so unforgiving, i have no idea what's going on! <?php $submit = (isset($_POST['submit'])) ? TRUE : FALSE; if(!$submit){ exit("You have not submmitted the form please go back!"); }else{ $name = (isset($_POST['name'])) ? $_POST['name'] : FALSE; $email = (isset($_POST['email'])) ? $_POST['email'] : FALSE; $email_check = "/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i"; $errors = array(); if(!$name){ $errors[] = "Please enter your name!"; } if(!$email){ $errors[] = "Please enter your email"; } if($email){ if(!preg_match($email_check,$email)){ $errors[] = "The email you entered is not valid!"; } } if(count($errors) > 0){ foreach($errors AS $error){ echo "$error <br />"; } }else{ $to = "Youremail@youremail.com"; $subject = "Your subject"; $email_content = " Name: ".$name."\n\n E-mail: ".$email." "; $header = "From: <$to>"; if($mail = mail($to,$subject,$email_content,$header)){ echo "Email has been sent thank you!"; }else{ echo "Could not send email!"; } } } ?> Ok there you go should work not tested yet if you have probs let me know You may also try my more secure contact form here if you like cheers Rizo Contact Form Mailer v1.5
March 24, 201016 yr Author thanks dude, i am plus 1ing you on the regular now. i'm gonna check your secure contact form out now as well.
March 24, 201016 yr thanks dude, i am plus 1ing you on the regular now. i'm gonna check your secure contact form out now as well. No prob if you have any problems with my contact form let me know
Create an account or sign in to comment