note 54340 deleted from ref.mail by mazzanet
| From: | mazzanet@php.net | Date: | Sun, 25 Dec 2005 23:27:14 +0000 |
| Subject: | note 54340 deleted from ref.mail by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-100697@lists.php.net to get a copy of this message | ||
Note Submitter: Arthur at 95070
----
When I tried to send email out from PHP script, I kept getting the following message, for all kinds
of reasons.
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header
missing in D:\htdocs\mailout.php on line 7
Before I finally made mail() work, I did lots of things, something good, others useless. The most
difficult part was that no matter what I did, the error message was all the same, until it finally
works.
If you see the message above, and you are running Apache on Windows first time, as I did, my
experience might help you.
(1)
First of all, make sure that you have a SMTP server is running. If you don't have a SMTP
installed, you get the same "From header" error message.
Use "Settings" - "Control Panel" - "Administrative Tools" -
"Services". You should see your Apache running there.
Look for "Simple Mail Transport Protocol (SMTP)", it is the SMTP server from Microsoft.
(2)
After install SMTP server, for easy testing, config it openly, that means everyone can use it.
Remember to change SMTP config to limit the access when you are done.
To test, you can use an email client to use your SMTP server's IP, and try to send out an
email.
Or you can use telnet to talk with your SMTP server. Microsoft has on-line help page about it:
http://support.microsoft.com/default.aspx?scid=kb;en-us;836500#5d
However, in the page the "rcpt" command is misspelled as "rpct", which results
in 'unknown command' error message.
That help page also has some security advice.
(3)
Config your PHP.
After installing Apache, there is no php.ini put in use. It runs happily with its defaults. Find
the "php.ini-dist" file, which has all the default values, and the PHP doc says that it is
for development environment, need to tight up security when go production.
What we need to set is the SMTP server address, and the "From" thing. For me, they are:
SMTP = 192.168.1.25
Sendmail_from = mailmaster@mydomain.com
I didn't touch the default port 25.
Save the changed version as php.ini, because that is the
name of the PHP config file Apache cares.
(4)
Reboot you Apache server, so the php.ini can take effect.
(5)
Here is the D:\htdocs\mailout.php test page I used.
<?PHP
$to = 'myaccount@freemail.com' ;
$subject = "smtp testing.";
$message = "Hi, there.";
mail($to, $subject, $message);
?>
(6)
change SMTP config to limit the access, nobody want to help spammers.