Reputation: 11
I am trying to set up a php script that would send an email to selected users, I looked on the internet and found out how but can't run the script cos I get the following error:
Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in E:\Program Files\xampp\phpMyAdmin\emailer.php on line 10
Here is the code of the script I designed following examples:
<?php
$recipient = "<[email protected]>";
$subject = "Flight Status";
$body = "Flight has just landed.";
$host = "ssl://smtp.gmail.com";
$port = "465";
if(mail($recipient, $subject, $body))
{
echo("<p>Message successfully sent</p>");
}
else
{
echo("<p>Message Delivery failed </p>");
}
?>
Thanks in advance.
Upvotes: 1
Views: 263
Reputation: 76910
As the error suggest you must add the default "from" field (who sends the mail) in php.ini:
SMTP = localhost
sendmail_from = [email protected]
And then restart apache
Otherwise you can set it dinamically as the fourth parameter as stated in the php manual (look http://php.net/manual/en/function.mail.php)
Note:
When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.
Example:
<?php
$to = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Upvotes: 1