使用PHPMailer for SMTP的问题 [英] Problem with using PHPMailer for SMTP

查看:101
本文介绍了使用PHPMailer for SMTP的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将PHPMailer用于SMTP,并且在发送带有错误邮件错误:以下发件人地址失败:no-reply@mydomain.org.uk"的邮件时出现问题

I have used PHPMailer for SMTP and there is problem in sending mail with error "Mailer Error: The following From address failed: no-reply@mydomain.org.uk"

我的代码如下:

        $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 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.

谢谢, Biplab

Thanks, Biplab

推荐答案

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 ...那是您的错误伙伴...:))

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

这篇关于使用PHPMailer for SMTP的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆