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 怎么获取下面的: glove_word2id.json和 glove_numpy.npy 这两个文件
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug