简体   繁体   中英

Problem with using PHPMailer for SMTP

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"

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

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... :))

try adding belowe line to php.ini

extension=php_openssl.dll

restart and try again

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM