【问题标题】:Not able to use phpmailer script for gmail无法为 gmail 使用 phpmailer 脚本
【发布时间】:2014-01-21 05:58:16
【问题描述】:

这是我的php 脚本:

<?php
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
include("../class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "x@gmail.com";
$mail->Password = "1234";
$mail->From = "y@gmail.com";
$mail->Subject = "Need Invitation";
$mail->Body = "invite me!";
$mail->AddAddress("x@gmail.com");
 if(!$mail->Send())
    {
    echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
    echo "Message has been sent";
    }
?>

执行此脚本后,我收到以下错误:

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1) 

我还启用了ssl

有很多问题与此非常相似,但没有从那里得到任何帮助。

【问题讨论】:

    标签: php ssl smtp openssl phpmailer


    【解决方案1】:

    尝试改变

    $mail->Host = "ssl://smtp.gmail.com";
    

    $mail->Host = "smtp.gmail.com";
    

    SSL 在网络模型中的运行级别不同于 HTTP、SMTP 等。

    您可能还需要将您的 SMTPSecure 设置从 'ssl' 更改为 'tls'

    【讨论】:

    • @AmitPal,您可能还需要将 SMTPSecure 设置从 'ssl' 更改为 'tls'
    • 收到此错误:SMTP -&gt; FROM SERVER: SMTP -&gt; FROM SERVER: SMTP -&gt; ERROR: EHLO not accepted from server: SMTP -&gt; FROM SERVER: SMTP -&gt; ERROR: HELO not accepted from server: SMTP -&gt; NOTICE: EOF caught while checking if connectedThe following From address failed: : Called Mail() without being connected Mailer Error: The following From address failed: : Called Mail() without being connected
    • @AmitPal,您是使用与您进行身份验证的From 相同的Gmail 帐户发送邮件,还是尝试使用与From 不同的电子邮件地址?
    • 我已使用电子邮件 -id 编辑了问题。请看一看。
    • @AmitPal,尝试为UsernameFrom 使用相同的电子邮件地址。我相信 Google 将其 SMTP 服务锁定为仅从经过身份验证的帐户发送。
    猜你喜欢
    • 1970-01-01
    • 2014-01-16
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2022-08-10
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多