Page 1 of 1

PHP mail() function

Posted: Sun Oct 03, 2010 5:20 pm
by lilpenguin
I just talked to my web host to make sure PHP was set up to send mail and it was. However, I get no errors. but I never get the email that should be sent when user fills out form. (the email address is stored in the $email variable).
Any ideas?
Thanks!

Code: Select all

<?
$headers .= 'To: $email' . "\r\n";
$headers .= "From:  <admin@mypage.com>" . "\r\n";
$to = $_POST['email']; 
$subject = "email confirmation"; 
$message = "This email is to advise you that you have successfully been 

registered . under $username and 

$password from this email address.  If you did not register or if this 

is an error, there is no need to respond to this email." ;

$sent=mail($to, $subject, $message, $headers); 

?>

[ /syntax] 

All variables were set from previous script.  Thanks again!




?>

Re: PHP mail() function

Posted: Sun Oct 03, 2010 5:24 pm
by John Cartwright
The mail() function is notoriously bad, and often requires the programmer to carefully construct the email headers.

The best option for mailing is to either use Swiftmailer(recommended) or PHPMailer (not as good as Swift, but simpler).