terri8787 Posted February 20, 2013 Share Posted February 20, 2013 I think I need a second set of eyes. I've done mail functions before in php with no problems but I can't get this one to work for anything. My success message populates after I hit send so it doesn't appear there are any errors. Any advice would be appreciated. <? php //If the form is submitted if(isset($_POST['submitted'])) { //Check to see if the honeypot captcha field was filled in if(trim($_POST['checking']) !== '') { $captchaError = true; } else { //Check to make sure that the name field is not empty if(trim($_POST['yourName']) === '') { $nameError = 'You forgot to enter your first name.'; $hasError = true; } else { $name = trim($_POST['yourName']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) === '') { $emailError = 'You forgot to enter your email address.'; $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $emailError = 'You entered an invalid email address.'; $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['comments']) === '') { $commentError = 'You forgot to enter your comments.'; $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['comments'])); } else { $comments = trim($_POST['comments']); } } //If there is no error, send the email if(!isset($hasError)) { $emailTo = 'territindle@hotmail.com'; $subject = 'Benefit Request from '.$name; $sendCopy = trim($_POST['sendCopy']); $body = "Name: $name \n\nEmail: $email \n\nComments: $comments"; $headers = 'From: The Website <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); if($sendCopy == true) { $subject = 'You emailed Your Name'; $headers = 'From: Your Name <territindle@hotmail.com>'; mail($email, $subject, $body, $headers); } $emailSent = true; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/274734-mail-function/ Share on other sites More sharing options...
requinix Posted February 20, 2013 Share Posted February 20, 2013 Have you checked the return values from mail()? If they're returning true then, as far as PHP is concerned, the emails have been sent - check your spam folder. Quote Link to comment https://forums.phpfreaks.com/topic/274734-mail-function/#findComment-1413696 Share on other sites More sharing options...
terri8787 Posted February 20, 2013 Author Share Posted February 20, 2013 'true' is being returned. Nothing in the junk/spam folder. I've tried several different email addresses in the to and from fields. This is a new server that was set up for us. PHP works on it as proved by using the 'echo' function. Is there some setting that has to be tweaked to allow emails to be sent? Quote Link to comment https://forums.phpfreaks.com/topic/274734-mail-function/#findComment-1413708 Share on other sites More sharing options...
AyKay47 Posted February 20, 2013 Share Posted February 20, 2013 Make sure the "mail function" options are set up correctly in the servers master php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/274734-mail-function/#findComment-1413730 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.