获取SMTP错误"无法连接到SMTP主机"在服务器上但在我的localhost上工作

时间:2017-02-19 12:35:23

标签: php email ssl smtp phpmailer

我正在使用phpmailer和gmail smtp,它正在为#34; tls"在我的本地xampp上,但当我在服务器邮件上移动我的项目时无法发送并给出错误:SMTP Error: Could not connect to SMTP host.

我的代码是:

                     $mail = new PHPMailer();
                    $mail->IsSMTP();
                    $mail->CharSet = 'UTF-8';
                    $mail->Host = "smtp.gmail.com";
                    $mail->SMTPAuth = true;
                    $mail->Port = 587; // Or 587
                    $mail->Username = $admin_email;
                    $mail->Password = $admin_password;
                    $mail->SMTPSecure = 'ssl';
                    $mail->From = $admin_email;
                    // $mail->FromName= $from_name;
                    $mail->isHTML(true);
                    $mail->Subject = $subject;
                    $mail->Body = $body;
                    $mail->addAddress($emailTo);
                    if (!$mail->send()){
                    echo "error"; 
                      }

我的代码有什么问题?

0 个答案:

没有答案