Jump to content

Mail Script Isn't Working


chibineku

Recommended Posts

I am trying to send an e-mail notification after resetting a user's password, and for some reason it won't send. This is the relevant code:

$headers = 'To:'.$email."\r\n";$headers .= 'From: webmaster@aromaclear.co.uk'."\r\n";$to = $email."\r\n";$subject = 'AromaClear Password Reset Notification'. "\r\n";$msg = 'From: AromaClear'."\r\n";$msg .='Subject: Your New Password'. "\r\n";$msg .= 'Message: Your new password is 	 '.$newpass."\r\n";$msg.= 'If you have received this e-mail in error, please ignore it.'. "\r\n";mail($to, $subject, $msg, $headers);

I'm sure it's something stupid...

Link to comment
Share on other sites

Now I'm trying this, and it's still not working!:

$headers = "To $email \r\n";$headers .= "From: chibineku@aol.com \r\n";$to = "$email \r\n";$subject = "AromaClear Password Reset Notification \r\n";$msg = "From: webmaster@aromaclear.co.uk \r\n";$msg .= "Subject: Your New Password \r\n";$msg .= "Message: Your new password is: $newpass \r\n";$msg.= "If you have received this e-mail in error, please ignore it.";// Mail itif(mail($to, $subject, $msg, $headers, "-f webmaster@aromaclear.co.uk")) {  header("Location: password_reset_redirect.php5?error=true".$email);  exit();} else {  header("Location: password_reset_redirect.php5?success=true".$email);  exit();}

I've tried every combination of \r\n, \r, \n that I can think of, tried using single quotes and double quotes, concatenating the variables where necessary, tried it without the -f parameter, and as far as I can tell, the e-mail sends, because the if clause always redirects with a pass. Please point me to my stupidity.

Link to comment
Share on other sites

Why is it redirecting to the error page if the mail sends successfully?

if(mail($to, $subject, $msg, $headers, "-f webmaster@aromaclear.co.uk")) {  header("Location: password_reset_redirect.php5?error=true".$email);  exit();} else {  header("Location: password_reset_redirect.php5?success=true".$email);  exit();}

Also, according to the RFC the mail body should be separated by only \n, while headers need a CrLf (\r\n).

Link to comment
Share on other sites

Ha, I have my conditions backwards! That's good news. So, what about the $to and $subject parts - do they need \r\n or \n or nothing?

Link to comment
Share on other sites

Fixed - thanks, my man. I can usually churn out big fairly (for me) complex scripts in no time, but the little things trip me up. Muchos gracies.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...