Reputation: 1337
Im sending emails with phpmail class, and for now Im just testing in localhost and it is working fine until today.
I was testing using a gmail adress and my send email configuration is like this:
define('MAILUSER','[email protected]');
define('MAILPASS','mytestpass');
define('MAILPORT','587');
define('MAILHOST','smtp.gmail.com');
And, with this configuration above I was sending mails witth sucess until today.
But now its not working, Im always getting this error: SMTP Error: Could not connect to SMTP host.
So I try to use a hotmail email to see if it works, and I really dont understand why but with hotmail Im sending emails with sucess, like this:
define('MAILUSER','[email protected]');
define('MAILPASS','mytestpass');
define('MAILPORT','25');
define('MAILHOST','smtp.live.com');
Do you see why this can be happening?
My function:
function sendMail($subject,$message,$from,$nameFrom,$to,$nameTo, $attachment = NULL, $reply = NULL, $replyNome = NULL){
require_once('mail/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->IsHTML(true);
$mail->SMTPSecure = "tls";
$mail->Host = MAILHOST;
$mail->Port = MAILPORT;
$mail->Username = MAILUSER;
$mail->Password = MAILPASS;
$mail->From = utf8_decode($from);
$mail->FromName = utf8_decode($fromName);
if($reply != NULL){
$mail->AddReplyTo(utf8_decode($reply),utf8_decode($replyNome));
}
$mail->Subject = utf8_decode($subject);
$mail->Body = utf8_decode($message);
$mail->AddAddress(utf8_decode($to),utf8_decode($nameTo));
if($attachment != NULL){
$mail->AddAttachment($attachment);
}
if($mail->Send()){
return true;
}
else{
return false;
}
}
Upvotes: 0
Views: 114
Reputation: 26
In you php.ini make sure you have uncommented the line with
(Windows)
extension=php_openssl.dll
(Linux)
extension=php_openssl.so
Also, for gmail, use this host :
$mail->Host = 'ssl://smtp.gmail.com:465';
Upvotes: 1
Reputation: 48357
It's not just a different port - you need to enable TLS as well. See http://phpmailer.worxware.com/?pg=examplebgmail
Upvotes: 1