note 54340 added to ref.mail
| From: | Arthurat95070 at osu1 dot php dot net | Date: | Thu, 30 Jun 2005 19:59:40 +0000 |
| Subject: | note 54340 added to ref.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91222@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/ref.mail.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54340
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54340&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54340&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54340&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54340&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54340&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54340&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54340&report=yes
Search -- http://master.php.net/manage/user-notes.php