PHP Mail function not working - deployed in Windows server
I am new to PHP, I have a website done in HTML and PHP. There is a form that sends mail. I have set up the Pear Mail package as per http://email.about.com/od/emailprogr...entication.htm
The following is my PHP file to send mail.
The mail function is failing. I get the response as "Email Delivery Failed" I have been searching on google for a day now, but havent found any solution. Thanks in advance.
// multiple recipients
$to = 'firstname.lastname@example.org' . ', '; // note the comma
$to .= 'email@example.com';
$subject = 'Birthday Reminders for August';
$message = '
<title>Birthday Reminders for August</title>
<p>Here are the birthdays upcoming in August!</p>
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <firstname.lastname@example.org>, Kelly <email@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <firstname.lastname@example.org>' . "\r\n";
$headers .= 'Cc: [email]email@example.com[/email]' . "\r\n";
$headers .= 'Bcc: [email]firstname.lastname@example.org[/email]' . "\r\n";
// Mail it
if(mail($to, $subject, $message, $headers))
echo("<p>Email successfully sent!</p>");
echo("<p> Email delivery failed </p>");
echo 'Caught Exception', $e->getMessage(), "\n";
Last edited by NogDog; 04-14-2014 at 03:57 PM.
Reason: added [php] tags around code
Welcome to the forums. Note that I added [php]...[/php] tags around your code so that it's easier for us to read. Please use applicable bbcode tags in your future posts. Now give me a minute or two to actually read your question and code...
a. You do not appear to actually be using PEAR::Mail, in case that is important to you. (You are simply using the built-in PHP mail() function.)
b. There is no reason to add a "To:" mail header to your $headers, since that is handled by the first parameter passed to mail(). I don't know if including it in your additional headers might be a problem or not.
c. Many mail servers will fail if the email address used for the "From:" header is not a valid email address on that server, so double-check that. (If you want replies to go to a different address, use the "Reply-To:" header for that.)
if i remember right, you can use one or the other, but not both. imo using the "To" in the headers parameter makes the most sense, esp. if you are bulk mailing.
Originally Posted by NogDog
if(!mail(NULL, $subject, $message, $additional_headers))
// mail() failed to send...
Try to use the PHP mail function like this:
$to = 'email@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: firstname.lastname@example.org' . "\r\n" .
'Reply-To: email@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Tried this but, I am still not getting the mail
Tried the above code but its not working. Mail function is returning false. Do I need to set up some configuration in IIS of the Windows Server?
Originally Posted by robertsullivan
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread