Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;                  

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
779 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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.

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!

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...