jelah Posted June 19, 2009 Share Posted June 19, 2009 Im really really new at php and ive got a form but the email is not sending, im sure its something simple but if anyone can take a look that would be great. <? // This function delivers a template with the error message function pgerror($string){ include 'head.inc'; echo "<font color=\"#FF0000\">Error: $string</font>"; include 'foot.inc'; exit(); } function pgsuccess($string){ include 'head.inc'; echo "<font color=\"green\">Thank you $string</font>"; include 'foot.inc'; exit(); } // These functions validate required feilds if (empty($_POST['first'])){ pgerror('Please enter your first name.'); } else { $first = $_POST['first']; } if (empty($_POST['last'])){ pgerror('Please enter your last name.'); } else { $last = $_POST['last']; } if (empty($_POST['address'])){ pgerror('Please enter your address.'); } else { $address = $_POST['address']; } if (empty($_POST['city'])){ pgerror('Please select your city.'); } else { $city = $_POST['city']; } if (empty($_POST['state'])){ pgerror('Please enter your state or province.'); } else { $state = $_POST['state']; } if (empty($_POST['postalcode'])){ pgerror('Please enter your postal code/zip code.'); } else { $postalcode = $_POST['postalcode']; } if (empty($_POST['country'])){ pgerror('Please select your country.'); } else { $country = $_POST['country']; } if (empty($_POST['email'])){ pgerror('Please enter your email.'); } else { $email = $_POST['email']; } if (empty($_POST['phone1'])){ pgerror('Please enter your phone number.'); } else { $phone1 = $_POST['phone1']; } if (empty($_POST['phone2'])){ pgerror('Please enter your phone number.'); } else { $phone2 = $_POST['phone2']; } if (empty($_POST['phone3'])){ pgerror('Please enter your phone number.'); } else { $phone3 = $_POST['phone3']; } if (empty($_POST['gender'])){ pgerror('Please enter your gender.'); } else { $gender = $_POST['gender']; } if (empty($_POST['why'])){ pgerror('Please complete all required feilds.'); } else { $why = $_POST['why']; } if (empty($_POST['reason1'])){ pgerror('Please complete all required feilds.'); } else { $reason1 = $_POST['reason1']; } if (empty($_POST['reason2'])){ pgerror('Please complete all required feilds.'); } else { $reason2 = $_POST['reason2']; } if (empty($_POST['reason3'])){ pgerror('Please complete all required feilds.'); } else { $reason3 = $_POST['reason3']; } pgsuccess('for your application!'); $todayis = date("l, F j, Y, g:i a") ; $subject = 'Photovoice Participant Application Form'; $notes = stripcslashes(" Name: $first $last\n Address: $address\n City: $city\n Province: $state\n Postal Code: $postalcode\n Country: $country\n Email: $email\n Phone: $phone1-$phone2-$phone3\n Gender (1=Male 2=Female): $gender\n Parent Permission: $party\n Parent Name: $parentnamefirst\n Why: $why\n Reason 1: $reason1\n Reason 2: $reason2\n Reason 3: $reason3\n "); $message = " $todayis [EST] \n Message: $notes \n "; $from = "From: $email\r\n"; mail("[email protected]", $subject, $message, $from); ?> Link to comment https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/ Share on other sites More sharing options...
jelah Posted June 19, 2009 Author Share Posted June 19, 2009 I tried this and it still isnt working // This function delivers a template with the error message function pgerror($string){ include 'head.inc'; echo "<font color=\"#FF0000\">Error: $string</font>"; include 'foot.inc'; exit(); } // These functions validate required feilds if (empty($_POST['first'])){ pgerror('Please enter your first name.'); } else { $first = $_POST['first']; } if (empty($_POST['last'])){ pgerror('Please enter your last name.'); } else { $last = $_POST['last']; } if (empty($_POST['address'])){ pgerror('Please enter your address.'); } else { $address = $_POST['address']; } if (empty($_POST['city'])){ pgerror('Please select your city.'); } else { $city = $_POST['city']; } if (empty($_POST['state'])){ pgerror('Please enter your state or province.'); } else { $state = $_POST['state']; } if (empty($_POST['postalcode'])){ pgerror('Please enter your postal code/zip code.'); } else { $postalcode = $_POST['postalcode']; } if (empty($_POST['country'])){ pgerror('Please select your country.'); } else { $country = $_POST['country']; } if (empty($_POST['email'])){ pgerror('Please enter your email.'); } else { $email = $_POST['email']; } if (empty($_POST['phone1'])){ pgerror('Please enter your phone number.'); } else { $phone1 = $_POST['phone1']; } if (empty($_POST['phone2'])){ pgerror('Please enter your phone number.'); } else { $phone2 = $_POST['phone2']; } if (empty($_POST['phone3'])){ pgerror('Please enter your phone number.'); } else { $phone3 = $_POST['phone3']; } if (empty($_POST['gender'])){ pgerror('Please enter your gender.'); } else { $gender = $_POST['gender']; } if (empty($_POST['why'])){ pgerror('Please complete all required feilds.'); } else { $why = $_POST['why']; } if (empty($_POST['reason1'])){ pgerror('Please complete all required feilds.'); } else { $reason1 = $_POST['reason1']; } if (empty($_POST['reason2'])){ pgerror('Please complete all required feilds.'); } else { $reason2 = $_POST['reason2']; } if (empty($_POST['reason3'])){ pgerror('Please complete all required feilds.'); } else { $reason3 = $_POST['reason3']; } $todayis = date("l, F j, Y, g:i a") ; $subject = 'Participant Application Form'; $notes = stripcslashes(" Name: $first $last\n Address: $address\n City: $city\n Province: $state\n Postal Code: $postalcode\n Country: $country\n Email: $email\n Phone: $phone1-$phone2-$phone3\n Gender (1=Male 2=Female): $gender\n Parent Permission: $party\n Parent Name: $parentnamefirst\n Why: $why\n Reason 1: $reason1\n Reason 2: $reason2\n Reason 3: $reason3\n "); $message = " $todayis [EST] \n Message: $notes \n "; $from = "From: $email\r\n"; mail("[email protected]", $subject, $message, $from); include 'head.inc'; echo "<font color=\"green\">Thank you for your application!</font>"; include 'foot.inc'; ?> Link to comment https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/#findComment-859401 Share on other sites More sharing options...
Ken2k7 Posted June 19, 2009 Share Posted June 19, 2009 Test if the mail function works or not. Create a new script with just this - <?php mail('[email protected]', 'subject', 'message'); That's it. Just change the email to your own and run the script. See if you get an email. Link to comment https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/#findComment-859404 Share on other sites More sharing options...
jelah Posted June 19, 2009 Author Share Posted June 19, 2009 thanks a lot that worked, everything is looking good accept one little thing, the from section of the email is not the email you enter in the form, am i missing something there as well? Link to comment https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/#findComment-859419 Share on other sites More sharing options...
Ken2k7 Posted June 19, 2009 Share Posted June 19, 2009 Change it to this - mail($email, $subject, $message, $from); Link to comment https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/#findComment-859422 Share on other sites More sharing options...
jelah Posted June 19, 2009 Author Share Posted June 19, 2009 I tried mail('[email protected]', $email, $subject, $message, $from); and now the email isnt sending again ??? Link to comment https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/#findComment-859427 Share on other sites More sharing options...
jelah Posted June 19, 2009 Author Share Posted June 19, 2009 ok, nvm i got it going, sorry im a big noob.. Thanks a lot for the help Link to comment https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/#findComment-859438 Share on other sites More sharing options...
jelah Posted June 19, 2009 Author Share Posted June 19, 2009 Ok apparently i didnt test it well enough... i had it wrong again, im just going to give this one more shot.. ive got the email coming from cgi-mailer and here is my code $todayis = date("l, F j, Y, g:i a") ; $subject = 'Participant Application Form'; $notes = stripcslashes(" Name: $first $last\n Address: $address\n City: $city\n Province: $state\n Postal Code: $postalcode\n Country: $country\n Email: $email\n Phone: $phone1-$phone2-$phone3\n Gender (1=Male 2=Female): $gender\n Parent Permission: $party\n Parent Name: $parentnamefirst\n Why: $why\n Reason 1: $reason1\n Reason 2: $reason2\n Reason 3: $reason3\n "); $message = " $todayis [EST] \n Message: $notes \n "; $from = "From: $email\r\n"; mail('[email protected]', $subject, $message); mail('[email protected]', $subject, $message); include 'head.inc'; echo "<font color=\"green\">Thank you for your application!</font>"; include 'foot.inc'; ?> When i change it to mail('[email protected]', $subject, $message, $from); the email wont send at all for some reason Link to comment https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/#findComment-859759 Share on other sites More sharing options...
whizzykid Posted June 20, 2009 Share Posted June 20, 2009 Hi men, I think you didnt define the mail function, as in $emai u didnt define it. Link to comment https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/#findComment-859970 Share on other sites More sharing options...
PFMaBiSmAd Posted June 20, 2009 Share Posted June 20, 2009 The From: email address needs to be an email address hosted at the sending mail server. When you tested without a value in the 4th parameter, it used a default email address that was probably valid for the sending mail server. You should put any email address entered on the form into the Reply-to: address and set the From: address to be a valid address on the sending mail server. Link to comment https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/#findComment-859973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.