首页 文章

PHPMailer没有给出错误信息?

提问于
浏览
0

我正在使用PHPMailer SMTP身份验证在瞬间创建一个小的电子邮件脚本 . 我现在尝试使用错误的密码发送电子邮件 - 但它仍然为成功提供“真实”......任何人都有任何想法?

这是My Function,我用来调用sendmail:

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

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

            return $response;
            $erfolg_email = false;

        }

    }

这是我的PHPMailer函数

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包含一个包含所有SMTP信息,电子邮件地址,签名,Smtp服务器,端口,用户名,密码和SSL使用情况的数组......

我很确定,我使用了错误的用户名和密码,因为没有电子邮件通过 - 但由于发送邮件功能我仍然得到“真实”...它甚至没有回应错误 . 当发送成功时我甚至尝试给出错误消息......但没有

任何帮助都是折旧的!

干杯

2 回答

  • 0

    您的函数 sendMail 不是数组/对象,在这种情况下结果总是 true . 尝试在if语句之前打印 $response ,您将看到错误 .

  • 0

    在您的php邮件程序功能文件中,您可以在最后添加此编码:

    $send = $mail->Send(); //Send the mails
        if($send){
            echo '<center><h3>Mail sent successfully</h3></center>';
        }
        else{
            echo '<center><h3>Mail error: </h3></center>'.$mail->ErrorInfo;
        }
    }
    

相关问题