I can't connect to SMTP GMAIL with PHPMailer.
here is error :
Error on Jun 25, 2015 22:54PM - stream_socket_client(): unable to connect to smtp.gmail.com:587 (Connection timed out) in /home/amiroper/public_html/beporsbedoon/app/helpers/phpmailer/smtp.php on line 222
and this is my code :
$this->_mail->isSMTP();
$this->_mail->Host = "smtp.gmail.com";
$this->_mail->SMTPAuth = true;
$this->_mail->Username = "amiroperator@gmail.com";
$this->_mail->Password = "*********";
$this->_mail->SMTPSecure = "tls";
$this->_mail->Port = "587";
$this->_mail->SMTPDebug = 4;
$this->_mail->From = "AmirOperator";
$this->_mail->FromName = 'amiroperator@gmail.com';
$this->_mail->addAddress("amiroperator@outlook.com", "test");
$this->_mail->isHTML(true);
$this->_mail->Subject = 'Registration confirm';
$this->_mail->Body = 'Thank you for registering to activate your account please click on this link. ".DIR."account/activate/$id/$activasion"';
$this->_mail->AltBody = 'Thank you for registering to activate your account please click on this link. ".DIR."account/activate/$id/$activasion"';
if(!$this->_mail->send()) {
$data['mailsent'] = false;
} else {
$data['mailsent'] = true;
}
the php code is wrong or this is connection problem
答案 0 :(得分:1)
答案 1 :(得分:1)
调整代码中的身份验证协议和端口号:
// Your Current Settings
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Updated Settings
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
我发现PHPMailer设置为使用带有TLS身份验证协议和端口号587的Gmail SMTP服务器时,根本不起作用。但是,我从来没有遇到过使用SSL / 465的问题。