简体   繁体   English

phpmailer-如何验证已发送电子邮件已到达目的地

[英]phpmailer - How to verify a sent email arrived at its destination

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. phpmailer工作正常,并且能够以多种方式使用它,但是.....我正在尝试寻找一种方法来确定是否有有效的电子邮件地址确实使它到达了某个目的地。 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... 这是我的设置通过gmail使用SMTP ...

$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;                  

If the email address looks like a duck and quacks like a duck then... 如果电子邮件地址看起来像鸭子而嘎嘎叫话,那么...
$result = $mail->send(); Will Always return true! 永远返回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??? 还是严格来说是通过Google的SMTP gmail服务器的一种单向喊叫???

Any tips, tricks, or pointers would be appreciated. 任何提示,技巧或指针,将不胜感激。

$mail->send() will not always return true. $mail->send() 并不总是返回true。 It returns true if the part of the sending process it was involved with works. 如果发送过程中涉及的部分工作,则返回true。 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. 因此,如果您发送到未知地址,但通过gmail发送,则gmail的服务器当时不知道该地址是否存在,因此该地址将被接受并在以后退回。 If you were sending to a gmail address when sending through gmail, then it would fail immediately. 如果您在通过gmail发送邮件时发送到gmail地址,那么它将立即失败。

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() ). 如果一个帐户根本不存在,大多数服务器(包括gmail)仍将给出5.1.1“未知用户”响应,如果您通过SMTP直接发送到收件人的假定邮件服务器,则PHPMailer将正确报告该响应(但如果通过中间服务器(例如gmail)或使用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. PHPMailer没有内置的支持,但您自己执行此操作仅涉及调用getmxrr并手动设置Host 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 (eg 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. 某些服务器会接受所有地址并在以后发送退回邮件(例如,如果它们的垃圾邮件过滤器的处理队列很长),但是如果您被预先拒绝,则可以肯定地表明该地址不存在。

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. 您还需要研究退回处理,这将允许您删除看起来不错但后来被证明不正确的地址,这与PHPMailer所做的任何事情完全不同。 I will warn you now - bounce handling is extremely unpleasant! 我现在警告您-弹跳处理非常不愉快!

You should also send using tls on port 587, not ssl on 465; 您还应该在端口587上使用tls发送,而不是在465上使用ssl发送; see the gmail example provided with PHPMailer. 请参阅PHPMailer随附的gmail示例。

You can ask for a receipt but the user has a choice and most people like me will not let it acknowledge receipt. 您可以要求收据,但用户可以选择,并且像我这样的大多数人都不会让它确认收据。 All you can do is to make sure all your headers are correct and monitor the bounced emails. 您所要做的就是确保所有标题正确,并监视退回的电子邮件。

The only reliable way to confirm delivery is to get the recipient to answer. 确认交付的唯一可靠方法是让收件人回答。 Tracking pixels don't work very well, or at all, and delivery receipts are often disallowed. 跟踪像素效果不佳,或者根本无法正常工作,并且通常不允许收货。 Bounced emails only identify dead mailboxes that generate a non-delivery report - not all do - and won't identify a mailbox that's active but ignored. 被退回的电子邮件仅标识出会生成未送达报告的无效邮箱(并非全部都如此),也不会标识处于活动状态但已被忽略的邮箱。 If the people you are emailing want something from you, don't give it to them until they've confirmed their address by responding to an email. 如果您要发送电子邮件的人想要您的东西,请在他们通过回复电子邮件确认其地址之前将其提供给他们。

Yes this can be done by - Using imap to read the bounced mail notification that gmail mailer-daemon sends back for undelivered mail and then parsing out the bogus address. 是的,这可以通过以下方式完成-使用imap读取gmail mailer-daemon发送回去的未送达邮件的退回邮件通知,然后解析出虚假地址。 Using that you can go back to your database and clean it up. 使用它,您可以返回数据库并进行清理。 My login/registration system will not require a valid email for basic access, but for elevated privileges it will. 我的登录/注册系统不需要有效的电子邮件即可进行基本访问,但是对于提升的特权却需要这样。 I'll just make an admin class function that processes privilege requests and also does database cleanup for basic accounts so there will be no lag-time for new user registration. 我将仅创建一个管理类功能,该功能处理特权请求,并且还对基本帐户进行数据库清理,因此新用户注册不会有任何滞后时间。

Thanks to all that had a look and contributed!!! 感谢所有看过并做出贡献的人!!! Now that I'm about done I'll have a look at getmxrr and see if that is better, but still plan to expand imap to automate email proxy account maintenance(deleteing, moving, ect...). 现在,我即将完成工作,我将看一下getmxrr ,看看效果是否更好,但仍计划扩展imap来自动执行电子邮件代理帐户维护(删除,移动等)。

The solution I found was : 我发现的解决方案是:
1) To save a copy of the email in a mysql database with an ID. 1)将电子邮件的副本保存在具有ID的mysql数据库中。
2) Make sure the email is signed with the domain in 1024 2)确保电子邮件已使用1024中的域签名
3) Add a img to the email requesting an image from a PHP file like https://www.example.com/img.php?id=emailid with the email ID instead of emailid 3)在电子邮件中添加img,以从PHP文件(例如https://www.example.com/img.php?id=emailid)中请求图像,并使用电子邮件ID代替emailid
4) In img.php get the email ID and update the corresponding entry of your database with the time and date and render a base64 image. 4)在img.php中获取电子邮件ID,并使用时间和日期更新数据库的相应条目,并渲染base64图像。

So now you can know when the email is open and the time and date. 现在,您可以知道何时打开电子邮件以及时间和日期。

Try this: 尝试这个:

if ( !PHPMailer::ValidateAddress($email) )

or 要么

if ( !$mail->validateAddress($email) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM