I can't seem to get my php script to send email.
<?php
echo "Does this page work?";
mail('my email address', 'test subject', 'test message');
?>
First, I have set the mail function settings in the php.ini file as follows:
I checked my email account settings on outlook. It does not require authentication, its port is 25, and its type of encrypted connection is 'Auto'. Given this I configured my php.ini file accordingly:
SMTP = ssl://smtp1.iis.com
smtp_port = 25
Then I set:
sendmail_from = my email address
The echo statement prints out in the browser, so I know the php file is recognized and processed. But the browser also shows the following error:
Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\mailtest.php on line 3
I have clearly set the sendmail_from so I don't know what else to do. I have also tried removing the 'ssl://' part from the SMTP setting in the php.ini file, and conf开发者_C百科iguring the php5.ini file. Which of these .ini files should I be configuring anyways?
You did uncomment sendmail_from
in php.ini
, yes? It should look like this:
; For Win32 only.
sendmail_from = me@example.com
Not like this:
; For Win32 only.
;sendmail_from = me@example.com
The only reason for PHP to say its not set .. is, well, if it's not set.
Edit
The only other issue that I could think of (for that warning) is that you may be editing the wrong php.ini file. If it's actually set , PHP should not be issuing that warning. I believe the default PHP configuration on your platform is \xampp\php\php.ini
Edit2
Your SMTP host may be using something called pop-before-smtp
. Try this using another mail provider that does use SMTP (password) authentication to rule that out.
To answer your question about 'which of these .ini files should I be configuring' you can run phpinfo() to see your server's configuration. That will list the paths to all of your config files.
sendmail_from = email@address.my
Mind the : should be a =
I now have an ANSWER to my question...
I used phpinfo() to find out which php.ini file I was supposed to be editing. As it turned out, there were 3 such files available in my server folder. Two were under the PhP folder (named php.ini and php5.in respectively) and the other was in the apache/bin folder. Using the phpinfo() function, I was able to determine that I was editing the wrong .ini files (I looked at the parameters I was setting and the were not changing). Once I edited the correct one (the one in apache/bin) the Warning: mail() [function.mail]: "sendmail_from"...error stopped occurring.
Then, to get the mail sent, I edited the correct .ini file as originally posed in my question:
SMTP = myoutgoingmail.com (the same setting as my mail program - outlook)
smtp_port = (the same as my mail program - oultook)
sendmail_from = myemailaddress.com
I hate to point out something so terribly obvious if it is an intentional misspelling, but in your SMTP line, shouldn't it be ssl://smtp1.iis.com ?
You need to pass a 'From' header for the mail() function. I believe the sendmail_from
setting only applies to Windows environments. Try this instead:
<?php
mail('email@example.com', 'Subject', 'Message', array('From' => 'me@example.com'));
?>
精彩评论