-1

I have a simple form script that's supposed to generate an email. It's been working just fine for about a year, but then I changed my hosting and now the script still redirects to the "thank you" page, but the email isn't generated. I don't think I've changed anything. Can y'all look over my script and see if there's anything wrong with it? Or is it the new hosting's fault?

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);  



 header( 'Location: http://amvleague.vitaminh.info/thankyou.html' ) ;

}
die();
?>
  • Please have a read of this http://stackoverflow.com/help/mcve - strip your code down to the bare `mail(..)` call and work from there – rjdown Mar 19 '15 at 16:42
  • Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Mar 19 '15 at 16:43
  • Alrighty, turns out it WAS godaddy's hosting - found this question on SO that saved the day: http://stackoverflow.com/questions/20972812/php-send-mail-form-not-working-with-emails-on-same-domain Thanks, everyone! – user3445044 Mar 19 '15 at 17:44

2 Answers2

0

According to the PHP mail function you can start by testing this code if it sends to your email. If you need mails with headers you can check on the PHP mail documentation for more example. If you did not receive any mails then you have problems with your hosting.

http://php.net/manual/en/function.mail.php

<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");

// Send
mail('caffeinated@example.com', 'My Subject', $message);
?>
Rex Adrivan
  • 897
  • 1
  • 10
  • 22
0

You have to test and handle if the mail action go well or not:

if( mail($email_to, $email_subject, $email_message, $headers)) {
// Ok my mail is well send I can redirect
    header( 'Location: http://amvleague.vitaminh.info/thankyou.html' ); 

} else {
// handle error
    print_r(mail($email_to, $email_subject, $email_message, $headers);
    die();
}
slig36
  • 173
  • 2
  • 12
  • Alright, I changed this in the PHP code, and now the redirect isn't happening - it just goes to a blank white screen. Any ideas where I should go from here? – user3445044 Mar 19 '15 at 17:01