Reputation: 11
I am working on a project in which I need to send email. My send mail function is:
ini_set('sendmail_path', "\"C:\xampp\sendmail\sendmail.exe\" -t");
ini_set('smtp_server', 'smtp.gmail.com');
ini_set('smtp_port', 25);
ini_set('smtp_ssl', 'auto');
ini_set('error_logfile', 'error.log');
ini_set('auth_username', '[email protected]');
ini_set('auth_password', 'mygmail_password');
//sendmail_from('[email protected]');
$to = '[email protected]';
$subject = 'Hello from XAMPP!';
$message = 'This is a test';
$headers = "From: [email protected]\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "SUCCESS";
} else {
echo "ERROR";
}
But I am getting following 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:\umtab\xampp\htdocs\umtab\email.php on line 23
Upvotes: 1
Views: 1438
Reputation: 191
As you can see from the error: you get Failed to connect to mailserver at "localhost" port 25. It's written localhost
, like the server is not properly set.
I think that ini_set('smtp_server', 'smtp.gmail.com');
is not working.
Try to use ini_set('SMTP','smtp.gmail.com');
instead ... that should be the correct way to set the SMTP server!
But anyway, as suggested by @ADyson, it would be better using PHPMailer. You can read the documentation and the usage right here.
Andrea
Upvotes: 1