使用 PHPMailer 进行 SMTP 的问题

发布于 2024-12-05 20:28:33 字数 1452 浏览 1 评论 0原文

我已将 PHPMailer 用于 SMTP,但发送邮件时出现问题,并出现错误“Mailer Error: The following From address failed: [email protected]"

我的代码如下:

        $mail = new PHPMailer();

        $mail->IsSMTP();                                   // send via SMTP

        $mail->Host = "localhost;"; // SMTP servers

        $mail->SMTPAuth = true;     // turn on SMTP authentication

        $mail->Username = "";  // SMTP username

        $mail->Password = ""; // SMTP password



        $mail->From = $email_address;

        $mail->FromName = $email_address;

        $mail->AddAddress($arrStudent[0]["email"]);

        $mail->WordWrap = 50;                              // set word wrap

        $mail->IsHTML(true);                               // send as HTML



        $mail->Subject = "Subject";

        $theData = str_replace("\n", "<BR>", $stuff);

        $mail->Body = $theData; // "This is the <b>HTML body</b>";

        $mail->AltBody = $stuff;




        if (!$mail->Send()) {

            $sent = 0;

            echo "Mailer Error: " . $mail->ErrorInfo;

            exit;

        }

我研究了所有内容,当我在 class.smtp.php 中调试时,我发现错误函数“get_lines()”返回错误值“550 身份验证失败”

代码以前工作正常,我想知道这个问题是怎么突然出现的。 迫切需要一些帮助。

谢谢, 双普拉实验室

I have used PHPMailer for SMTP and there is problem in sending mail with error "Mailer Error: The following From address failed: [email protected]"

My code is as follows:

        $mail = new PHPMailer();

        $mail->IsSMTP();                                   // send via SMTP

        $mail->Host = "localhost;"; // SMTP servers

        $mail->SMTPAuth = true;     // turn on SMTP authentication

        $mail->Username = "";  // SMTP username

        $mail->Password = ""; // SMTP password



        $mail->From = $email_address;

        $mail->FromName = $email_address;

        $mail->AddAddress($arrStudent[0]["email"]);

        $mail->WordWrap = 50;                              // set word wrap

        $mail->IsHTML(true);                               // send as HTML



        $mail->Subject = "Subject";

        $theData = str_replace("\n", "<BR>", $stuff);

        $mail->Body = $theData; // "This is the <b>HTML body</b>";

        $mail->AltBody = $stuff;




        if (!$mail->Send()) {

            $sent = 0;

            echo "Mailer Error: " . $mail->ErrorInfo;

            exit;

        }

i researched everything and when i debug inside class.smtp.php i found error the function "get_lines()" is returning error value "550 Authentication failed"

The code was working fine previously, i am wondering how this problem came suddenly.
Desperate for some help.

Thanks,
Biplab

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

成熟稳重的好男人 2024-12-12 20:28:33
public function sendEmail ( $subject, $to, $body, $from = FALSE ) {
    require_once('mailer.class.php');
    $mailer = new PHPMailer();
    //do we use SMTP?
    if ( USE_SMTP ) {
        $mailer->IsSMTP();
        $mailer->SMTPAuth = true;
        $mailer->Host = SMTP_HOST;
        $mailer->Port = SMTP_PORT;
        $mailer->Password = '';
        $mailer->Username = '';
        if(USE_SSL)
            $mailer->SMTPSecure = "ssl";
    }

    $mailer->SetFrom($from?$from:ADMIN_EMAIL, ADMIN_NAME);
    $mailer->AddReplyTo ( ADMIN_EMAIL, ADMIN_NAME );

    $mailer->AddAddress($to);
    $mailer->Subject = $subject;
    //$mailer->WordWrap = 100;
    $mailer->IsHTML ( TRUE );
    $mailer->MsgHTML($body);

    require_once('util.class.php');
    $mailer->AltBody  =  Util::html2text ( $body );

    //$mail->AddAttachment("images/phpmailer.gif");      // attachment
    //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

    if ( ! $mailer->Send() ) {
        return FALSE;
    }
    else {
        $mailer->ClearAllRecipients ();
        $mailer->ClearReplyTos ();
        return TRUE;
    }
}

我已经这样使用了... SetFrom 应该用来代替 From...那是你的错误伙伴...:))

public function sendEmail ( $subject, $to, $body, $from = FALSE ) {
    require_once('mailer.class.php');
    $mailer = new PHPMailer();
    //do we use SMTP?
    if ( USE_SMTP ) {
        $mailer->IsSMTP();
        $mailer->SMTPAuth = true;
        $mailer->Host = SMTP_HOST;
        $mailer->Port = SMTP_PORT;
        $mailer->Password = '';
        $mailer->Username = '';
        if(USE_SSL)
            $mailer->SMTPSecure = "ssl";
    }

    $mailer->SetFrom($from?$from:ADMIN_EMAIL, ADMIN_NAME);
    $mailer->AddReplyTo ( ADMIN_EMAIL, ADMIN_NAME );

    $mailer->AddAddress($to);
    $mailer->Subject = $subject;
    //$mailer->WordWrap = 100;
    $mailer->IsHTML ( TRUE );
    $mailer->MsgHTML($body);

    require_once('util.class.php');
    $mailer->AltBody  =  Util::html2text ( $body );

    //$mail->AddAttachment("images/phpmailer.gif");      // attachment
    //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

    if ( ! $mailer->Send() ) {
        return FALSE;
    }
    else {
        $mailer->ClearAllRecipients ();
        $mailer->ClearReplyTos ();
        return TRUE;
    }
}

I've used like that... SetFrom should be used in place of From... that's your error buddy... :))

┊风居住的梦幻卍 2024-12-12 20:28:33

尝试将以下行添加到 php.ini

extension=php_openssl.dll

restart 并重试

try adding belowe line to php.ini

extension=php_openssl.dll

restart and try again

偏闹i 2024-12-12 20:28:33

我正在使用 YII 的 Mailer 和 PHPMailer,这对我有用:

$mail = Yii::createComponent('application.extensions.mailer.EMailer');
$mail->Username           = $this->SMTP_USERNAME;  // SMTP username
$mail->Password           = $this->SMTP_PASSWORD; // SMTP password
$mail->SMTPAuth           = true;
$mail->From               = $this->fromAddress;
$mail->Host               = $this->SMTP_SERVER_ADDRESS;
$mail->FromName           = $this->fromName;
$mail->CharSet            = 'UTF-8';
$mail->Subject            = Yii::t('mailer', $this->subject);
$mail->Body               = $this->message;
$mail->AddReplyTo($this->toAddress);
$mail->AddAddress($this->toAddress);
$mail->IsSMTP(true);
$mail->IsHTML(true);
$mail->Send();

希望有帮助吗?

I am using YII's Mailer with PHPMailer, and this works for me:

$mail = Yii::createComponent('application.extensions.mailer.EMailer');
$mail->Username           = $this->SMTP_USERNAME;  // SMTP username
$mail->Password           = $this->SMTP_PASSWORD; // SMTP password
$mail->SMTPAuth           = true;
$mail->From               = $this->fromAddress;
$mail->Host               = $this->SMTP_SERVER_ADDRESS;
$mail->FromName           = $this->fromName;
$mail->CharSet            = 'UTF-8';
$mail->Subject            = Yii::t('mailer', $this->subject);
$mail->Body               = $this->message;
$mail->AddReplyTo($this->toAddress);
$mail->AddAddress($this->toAddress);
$mail->IsSMTP(true);
$mail->IsHTML(true);
$mail->Send();

Hope that helps?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文