I am struggling to send mails through PHP, running on IIS7. I have an SMTP server running on the server which I can access through telnet and send a mail through with no problems, and php.ini is configured as follows:
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
When I run a simple PHP script to test the mail function:
$to = "test@email.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
if(mail($to,$subject,$message,$headers))
{
echo('ok');
}
else
{
echo('not ok');
}
ok is returned however no mail is received. I have set error_reporting(-1); and am getting no errors or warnings either. I’m stumped as to what could wrong?
I’ve just found the issue – it was the sendmail_from setting in php.ini. Even though the script is not using this value it seems like it has to be a well formed email address however it wasn’t. Setting it to test@mail.com and restarting the site has done the trick