简体   繁体   English

连接失败。 错误 #2:stream_socket_client():无法连接到 ssl://smtp.gmail.com:465(连接被拒绝)

[英]Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)

I'm trying to use PHPMailer but I'm getting the following error:我正在尝试使用PHPMailer但出现以下错误:

Connection failed.连接失败。 Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)错误 #2:stream_socket_client():无法连接到 ssl://smtp.gmail.com:465(连接被拒绝)

Here is my code:这是我的代码:

$mail = new PHPMailer;
$mail->SMTPDebug = 4;                               // Enable verbose debug  output
$mail->isSMTP();                                      // Set mailer to use SMTP  
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication  
$mail->Username = 'test@gmail.com';                 // SMTP username
$mail->Password = 'some_password';                           // SMTP password  
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted  
$mail->Port = 465;                                    // TCP port to connect to  
$mail->setFrom('earndreamsol@gmail.com' );
$mail->addAddress($email);     // Add a recipient      
//$mail->addReplyTo($email, $name);  
$mail->isHTML(true);                                  // Set email format to HTML  
$mail->Subject = "Email from Alahmed & Co";  
$mail->Body    = " Thanks For Subscribe Alahamed & co"; 
$mail->AltBody = "Thanks For Subscribe Alahamed & co";
if(!$mail->send()) {  
    echo 'Message could not be sent.';  
    echo 'Mailer Error: ' . $mail->ErrorInfo;  
} else {  
    $_SESSION['msg']="you are successfully subscribed !!";  
    $_SESSION['msg1']="you are successfully subscribed !!";
    header("location:index.php#newssection");
}

Have you try to use :你有没有尝试使用:

$mail->SMTPSecure = 'tls';

and/or :

$mail->Port = 587;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Connection could not be established with host smtp.gmail.com:stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 - Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 如何解决错误:消息:fsockopen():无法连接到 ssl://smtp.gmail.com:465(连接被拒绝) - How to resolve the error: Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused) 在Codeigniter中无法发送电子邮件-fsockopen():无法连接到ssl://smtp.gmail.com:465(连接被拒绝) - in Codeigniter Unable to send email - fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused) 无法使用 smtp.gmail.com 建立 Swift_TransportException 连接 stream_socket_client():无法连接到 tls://smtp.gmail.com:587 - Swift_TransportException Connection could not be established with smtp.gmail.com stream_socket_client(): unable to connect to tls://smtp.gmail.com:587 PHP Fatal error: Uncaught Swift_TransportException: Connection could not be established with host ssl://smtp.gmail.com:stream_socket_client() - PHP Fatal error: Uncaught Swift_TransportException: Connection could not be established with host ssl://smtp.gmail.com :stream_socket_client() [SMTP:无法连接套接字:fsockopen():无法连接至ssl://smtp.gmail.com:465(未知错误)(代码:-1,响应:)] - [SMTP: Failed to connect socket: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) (code: -1, response: )] 消息:fsockopen():无法连接到ssl://smtp.gmail.com:465(连接超时) - Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection timed out) Getting "Connection could not be established with host smtp.gmail.com:stream_socket_client()" error in laravel 8 on localhost for sending email - Getting "Connection could not be established with host smtp.gmail.com :stream_socket_client()" error in laravel 8 on localhost for sending email stream_socket_client():无法连接到ssl://gateway.sandbox.push.apple.com:2195(连接被拒绝) - stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) 在php stream_socket_client()中获取错误:无法连接到ssl://gateway.sandbox.push.apple.com:2195(连接被拒绝) - getting error in php stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM