tags:

views:

136

answers:

6

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 configuring the php5.ini file. Which of these .ini files should I be configuring anyways?

A: 

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://*smtp*1.iis.com ?

melee
fixed the typo - thanks for pointing it out
RoryG
No problem, wasn't sure if you hand-typed it or copied and pasted it over.. Sometimes it just takes a second pair of eyes.
melee
A: 

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 protected]', 'Subject', 'Message', array('From' => '[email protected]'));
?>
loginx
I don't think php would be complaining about it being unset if he was not on a Windows environment. Additionally, the warning references a Windows path name.
Tim Post
tried that - it didn't work. I am in a windows environment so I am guessing the 'From' header does the same thing as the php.ini configuration
RoryG
+1  A: 

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.

rizzletang
so I ran phpinfo() and noted that I am running php5.2.5 so I assume I should be editing the php5.ini?More intriguingly, I looked down at the specs and one read:SMPT localhostBut that is the one I think I am changing to something else (as indicated in my original question). This may be a clue to my problem! Thanks
RoryG
When you look at the `phpinfo()` page, the sixth row on the very first table (the one at the top of the page) lists the "Configuration File (php.ini) path". The file listed there is the file used in configuration. Make sure that's the one you're editing!
eykanal
+3  A: 

You did uncomment sendmail_from in php.ini, yes? It should look like this:

; For Win32 only.
sendmail_from = [email protected]

Not like this:

; For Win32 only.
;sendmail_from = [email protected]

The only reason for PHP to say its not set .. is, well, if its 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 its 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.

Tim Post
yes - though that took me a few looks before I noticed it...didn't help
RoryG
@RoryG Its very likely that you are editing the wrong php.ini file if your changes aren't reflecting in `phpinfo()`
Tim Post
Yep - I came to that conclusion and now the warning has stopped, but still no email is being sent...For others who may have the same problem, it turned out for my platform anyways, its \xampp\apache\bin\php.ini
RoryG
A: 
sendmail_from = [email protected]

Mind the : should be a =

Phliplip
fixed that typo too. I should have cut and paste, but didn't want to expose my details...
RoryG
No problem, wasn't sure if you hand-typed it or copied and pasted it over.. Sometimes it just takes a second pair of eyes. :-P
Phliplip
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
RoryG