tags:

views:

116

answers:

3

I am trying to get this simple php mail script to send mail to my email addres ([email protected]) and I cannot get it to work. I set my sendmail_path in php.ini to the right folder (/etc/sbin/sendmail) but that did not seem to help. What else could I be missing? The script always returns failure.

<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
if(mail($to,$subject,$message,$headers))
    echo "Mail Sent.";
else
    echo "failure";
?>
A: 

In case anyone else comes to this question via google, another main cause of php mail not working is that the function is blocked on many servers due to the danger of outgoing spam.

There are some good smtp mail classes out there that are very easy to use. I only use mail() for debugging purposes... almost never in a live environment.

Citizen
+1  A: 

SwiftMailer is a good library for the purpose of authenticating to your SMTP server to send mail.

http://swiftmailer.org/

Kyle Ridolfo
+1  A: 

try to use PEAR MAIL package.

Anas Toumeh