I use the PHP mail() function in a program to send email. This is the code:
<?php
ini_set ('SMTP', 'my.domain');
mail ("[email protected]", "PHP mail function", "Body of email", "From:[email protected]");
?>
I get this error:
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\mail.php on line 41
I have made sure the SMTP and smtp_port setting in php.ini are set:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
Why am I receiving this error?
phpinfo()to ensure your SMTP settings are actually what you think they are. Sometimes you edit PHP.ini and due to a syntax error or unprintable character, your settings don't load. Or, you edited the wrong file. - BradC:\mail.php). You need to setup access to an SMTP service, probably a 3rd party one (like login and send with Gmail). It is very highly recommended not to usemail()and instead use a class like PHPMailer. phpmailer.worxware.com - Michael Berkowski