I am trying to use the native PHP function to send a simple test email through gmail SMTP, but it's not working. Going through various forums including Stack Overflow and the only solutions I see are the ones that recommend third-party email libraries/frameworks/api's. Does this mean that PHP's mail()
does not work with Gmail, and if so, why?
The following is the code:
<?php
$to ="mail2@yahoo.com";
$sbj ="test mail";
$msg ="testing! testing!! testing!!!";
ini_set("SMTP", "ssl://smtp.gmail.com");
ini_set("smtp_port", 465);
ini_set("sendmail_from", "mail1@gmail.com");
$header ="From: " .ini_get("sendmail_from");
mail($to, $sbj, $msg, $header);
?>
And the error message I got:
Warning: mail(): Failed to connect to mailserver at "ssl://smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\test\web1\test1.php on line 12