PHP mail() function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lilpenguin
Forum Newbie
Posts: 18
Joined: Sun Sep 19, 2010 7:06 pm

PHP mail() function

Post 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!




?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: PHP mail() function

Post 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).
Post Reply