无法连接到服务器:连接超时(110)SMTP连接()失败。消息未发送.Mailer错误:SMTP Connect()失败

时间:2013-09-03 09:36:09

标签: phpmailer php

这是我的代码,但仍然没有发送邮件。可能是什么问题?

require 'class.phpmailer.php';// path to the PHPMailer class
require 'class.smtp.php';

            $mail = new PHPMailer();  

            $mail->IsSMTP();  // telling the class to use SMTP
            $mail->Mailer = "smtp";
            $mail->Host="smtp.gmail.com";
            $mail->SMTPSecure='tls';
            $mail->Port =465;             
            $mail->SMTPAuth = true; // turn on SMTP authentication
            $mail->Username = "mymailgmail.com"; // SMTP username
            $mail->Password = "mypassword"; // SMTP password 
            $mail->SMTPDebug = 1;

            $mail->AddAddress("mymail@gmail.com","Title");
            $mail->SetFrom($visitor_email, $name);
            $mail->AddReplyTo($visitor_email,$name);

            $mail->Subject  = "Message from  Contact form";
            $mail->Body     = $user_message;
            $mail->WordWrap = 50;  

            if(!$mail->Send()) {
            echo 'Message was not sent.';
            echo 'Mailer error: ' . $mail->ErrorInfo;
            } else {
            echo 'Message has been sent.';
            }

// header('Location:thank-you.html');     }

1 个答案:

答案 0 :(得分:1)

有时候我有类似的问题。事实证明,使用ipv6地址尝试连接。从网络接口删除IPv6地址后,它工作正常。