doufuxi7093 2016-04-28 11:56
浏览 45
已采纳

PHPMailer没有给出错误信息?

Im creating a little Email Script at the Moment with PHPMailer + SMTP Authentication. I tried now sending an E-Mail using a wrong Passwort - but it still gives back "true" for success... anyone have any idea?`

Here is My Function, that i use to call sendmail:

$erfolg_email = true;
    foreach($empfaenger as $value)
    {

        $response = $this->sendMail($smtp, $value, $content, $files);
        if($response != true)
        {

            return $response;
            $erfolg_email = false;

        }

    }

And here is my PHPMailer Function

function sendMail($smtp, $empfaenger, $content, $attachements)
{

    $mail = new PHPMailer(true);

    try{

        $mail->IsSMTP();    
        $mail->Host = $smtp['SMTP'];
        $mail->SMTPAuth = true;     // turn on SMTP authentication
        $mail->Port = $smtp['Port'];
        $mail->SMTPSecure = 'tls';
        if($smtp['Domain'] != '')
        {

            $username = $smtp['Username']."@".$smtp['Domain'];

        }else
        {

            $username = $smtp['Username'];

        }
        $mail->Username = $username;  // SMTP username
        $mail->Password = $smtp['Password']; // SMTP password
        $mail->SMTPOptions = array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        );
        $mail->From = $smtp['Email_Address'];
        $mail->AddAddress($empfaenger);
        $mail->WordWrap = 50;
        $mail->isHTML(true);

        foreach($attachements as $value)
        {

            $mail->AddAttachment($value);

        }
        $mail->Subject = "Mahnung";
        $mail->Body = $content;
        $mail->AltBody = "Sie haben offene Posten";

        if($mail->Send() == true)
        {

            echo $mail->ErrorInfo;
            return $mail->ErrorInfo;

        }else
        {

            return $mail->ErrorInfo;

        }

    } catch (phpmailerException $e) {

        return $e->errorMessage(); //Pretty error messages from PHPMailer

    } catch (Exception $e) {

        return $e->getMessage(); //Boring error messages from anything else!

    }
}

$smtp contains an array with all the SMTP INformation, Email address, Signature, Smtp Server, Port, Username, Password and SSL Usage...

I am pretty sure, I am using the wrong username and password, as no Email is getting through - but i still get "true" as a result of the send mail function... its not even echoing the error. I did even try to give an Error Message, when sending is successfull... But nothing

Any help is apreciated!

Cheers

  • 写回答

2条回答 默认 最新

  • duanmie9741 2016-04-28 12:01
    关注

    Your function sendMail doesn't return a boolean. Since it's an array / object the result is always true in this case. Try printing $response before your if statement and you will see the error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败