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.
The solution I found was :
1) To save a copy of the email in a mysql database with an ID.
2) Make sure the email is signed with the domain in 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
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.
So now you can know when the email is open and the time and date.
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. 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...).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.
$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 togetmxrr
and settingHost
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, notssl
on 465; see the gmail example provided with PHPMailer.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.
Try this:
or