我现在正在用PHPMailer+SMTP身份验证创建一个小的电子邮件脚本。我现在试着用错误的Passwort发送电子邮件,但它仍然会为成功回报"真实"。。。有人知道吗
这是我的函数,我用它来调用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用法。。。
我很确定,我使用了错误的用户名和密码,因为没有电子邮件通过-但由于发送邮件功能,我仍然得到了"true"。。。它甚至没有回应错误。当发送成功时,我甚至试图发出错误消息。。。但没有
任何帮助都是值得的!
干杯
函数sendMail
不返回布尔值。由于它是一个数组/对象,因此在这种情况下,结果总是true
。尝试在if语句之前打印$response
,您会看到错误。
在php mailer函数文件中,您可以在最后添加以下代码:
$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;
}
}