Problem with using PHPMailer for SMTP

前端 未结 3 930
陌清茗
陌清茗 2021-01-26 16:30

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 a

3条回答
  •  时光说笑
    2021-01-26 16:42

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

提交回复
热议问题