phpmailer-如何验证已发送电子邮件已到达目的地 [英] phpmailer - How to verify a sent email arrived at its destination

查看:207
本文介绍了phpmailer-如何验证已发送电子邮件已到达目的地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

phpmailer可以正常工作,并且能够以多种方式使用它,但是....我正在尝试寻找一种方法来确定是否有有效的电子邮件地址确实使它到达了某个目的地.我正在谈论验证地址,例如...
if (!$mail->validateAddress($email)) {echo 'Not a valid squiloople email pattern';}

这是我的设置是通过gmail使用SMTP ...

phpmailer is working fine and able to use it in various ways, but.... I'm trying to find a way to determine if a valid looking email address actually made it to some destination. I am NOT talking about validating addresses such as...
if (!$mail->validateAddress($email)) {echo 'Not a valid squiloople email pattern';}

This is my setup is using SMTP through gmail...

$mail->isSMTP();                        
$mail->SMTPAuth = true; 
$mail->SMTPDebug = 0;                   
$mail->isHTML(true);
$mail->Host = 'smtp.gmail.com';         
$mail->Username = "XXXl@gmail.com";  
$mail->Password = "XXX";    
$mail->SMTPSecure = 'ssl';              
$mail->Port = 465;                  

如果电子邮件地址像鸭子一样,嘎嘎叫鸭子,那么...
$result = $mail->send();始终返回true!
var_dump($mail->send()); // Also returns Boolean

有没有一种方法可以测试电子邮件是否确实在某处收到?还是严格地说是通过Google的SMTP gmail服务器的一种单向喊叫???

任何提示,技巧或指针,将不胜感激.

If the email address looks like a duck and quacks like a duck then...
$result = $mail->send(); Will Always return true!
var_dump($mail->send()); // Also returns Boolean

Is there a way to test if the email was actually received somewhere? Or is this strictly a one-way shout-out through google's SMTP gmail servers???

Any tips, tricks, or pointers would be appreciated.

推荐答案

$mail->send()始终返回true.如果发送过程中涉及的部分有效,则返回true.因此,如果您发送到未知地址,但通过gmail发送,则gmail的服务器当时不知道该地址是否存在,因此该地址将被接受并在以后退回.如果您在通过gmail发送邮件时发送到gmail地址,那么它将立即失败.

$mail->send() will not always return true. It returns true if the part of the sending process it was involved with works. So if you send to an unknown address, but do so via gmail, gmail's servers don't know whether the address exists or not at the time, so it will be accepted and bounced later. If you were sending to a gmail address when sending through gmail, then it would fail immediately.

如果根本不存在任何帐户,大多数服务器(包括gmail)仍将给出5.1.1未知用户"响应,并且如果您通过SMTP直接发送给收件人的假定邮件,PHPMailer将正确报告该响应服务器(但是如果您是通过中间服务器(例如gmail)或使用mail()发送的,则不会). PHPMailer没有内置的支持,但是您自己执行此操作仅涉及调用 getmxrr 并手动设置Host.同样,如果您以这种方式发送,则无需使用身份验证.

If an account does not exist at all, most servers (including gmail) will still give a 5.1.1 "Unknown user" response, and that will be reported correctly by PHPMailer if you send by SMTP directly to the recipient's supposed mail server (but not if you send via an intermediate server (like gmail) or using mail()). PHPMailer doesn't have built-in support for doing that, but doing it yourself only involves a call to getmxrr and setting Host manually. Also you won't need to use authentication if you send that way.

您可以执行各种操作,例如检查某个域是否存在-如果不存在,则邮件传递将不起作用.某些服务器会接受所有地址并在以后发送退回邮件(例如,如果它们的垃圾邮件过滤器的处理队列很长),但是如果您被预先拒绝,则可以肯定地表明该地址不存在.

You can do various things like check if a domain exists at all - if it doesn't, mail delivery won't work. Some servers will accept all addresses and send bounces later (e.g. if they have a spam filter with a long processing queue), but if you get rejected up-front, it's a pretty sure indication that the address doesn't exist.

您还需要研究退回处理,这将允许您删除看起来不错但后来被证明不正确的地址,这与PHPMailer所做的一切完全不同.我现在警告您-弹跳处理非常不愉快!

You need to look into bounce handling too which will allow you to remove addresses that looked ok but later proved not to be, which is an entirely separate thing from anything that PHPMailer does. I will warn you now - bounce handling is extremely unpleasant!

您还应该在端口587上使用tls发送,而不是在465上使用ssl发送;请参阅PHPMailer随附的gmail示例.

You should also send using tls on port 587, not ssl on 465; see the gmail example provided with PHPMailer.

这篇关于phpmailer-如何验证已发送电子邮件已到达目的地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆