phpmailer forces Mail delivery failed to reply-to and not from - phpmailer

I'm using phpmailer on my ERP and the from email is a noreply# and the reply-to is my client/company email.
Sometimes I'm receiving "Mail delivery failed: returning message to sender" that is normal but I'm receiving those to my noreply# and not the client email.
How can I force the phpmailer to send the "Mail delivery failed" to reply-to email?
Thank you for your help.

Bounces go to the return-path, not the reply-to address, because they are bounces, not replies.
It's not PHPMailer that's sending your bounces there, it's the receiver, and they are acting correctly.
You can set the return path indirectly using the Sender property which is used to set the envelope sender, which the receiver converts into a return-path before attempting delivery. Do not be tempted to set a return-path header yourself; it's the receiver's job.
$mail->Sender = 'bounces_go_here#example.com';
Beware though – this address is what SPF applies to, so you need to be very sure that your SPF records are set up correctly. For reliable bounce handling, I'd recommend making use of VERP addressing here too.

Related

PHPMailer bounce email address shows in sender mailbox

I am using a PHP script to send emails using PHPMailer (on an ovh web server).
With the following script :
$mail->isMail();
......
$mail->addReplyTo('postmaster#mydomain.fr', 'Site');
$mail->SetFrom('postmaster#mydomain.fr', 'Site');
Emails get delivered to my gmail account BUT not to other addresses (e.g. my Business email).
With the following script :
$mail->isMail();
......
$mail->addReplyTo('postmaster#mydomain.fr', 'Site');
$mail->Sender = 'postmaster#mydomain.fr';
Emails get delivered to other addresses (e.g. my Business email) BUT not to gmail.
Also the sender appears as
bounce-id=D004=U58180. …… .net
which is not so friendly.
Is there a way to solve those issues ?
Using setFrom by itself will result in Sender being set to the same value as your from address (look at the code in the setFrom method). So in your second example you're setting the envelope sender, but not the from address, which is likely not what you want.
You may find it easier to use SMTP to localhost instead of isMail(); just changing that method to isSMTP() should be enough to do that. That way you can set SMTPDebug = 2 and see exactly what your local mail server is saying.
Separately, you don't need to set a reply-to address if it's the same as your from address – PHPMailer will simply ignore it if you try to set them to the same value anyway.

Can I reply my own mails with PHPMailer, that's possible?

I need a information about PHPMailer about replying my own mails.
I need send a empty mail(subject, body), and when the first mail sent second mail need sending with replying first mail.
That's possible ?
I tried but never can repyling my own mails.
Yes, but PHPMailer won't do this for you. You will need to do it by getting and setting appropriate headers, in particular the Message-ID header that identifies each message, and the In-Reply-To and References headers which are used to track whether something is a reply. Probably the best way to see these working is to simulate it using your regular email client - Outlook, Gmail, Apple Mail – all of which will set those headers correctly.

SendGrid/Outlook receiving 50% of emails

I've just set up SendGrid, authentificated my domain and did the sender verification.
I use Node.js to send email via the API.
When I make a test, the mail is sent to my outlook address. It takes 3 seconds to appear in Outlook, not in spam, in my inbox.
However, when I make the same test, 30 seconds later, the mail is processed by SendGrid, but I never receive in Outlook..
How can it be possible ?
please check your sendgrid activity tab. Processed doesnt mean that outlook received it. After processed there is another level of delivered. Does it say in your sendgrid activity log that it was delivered. It might say not and outlook refused it because they think one email after the other might be spam. (Keep this in mind when sendgrid sends emails it doesnt come from your email address, and some might mark that as spam)

Unable to send email to office 365 via linux command

I am trying to send email via linux command line using following command
echo "This is body part" | mail -s "this is subject" username#domain.com
If I send to gmail it works but if i send to office365 it does not work.
Could you help me?
This can also quite often be because of the mail relay server you are using (where the SMTP mail is routing through from the Linux box) not having been set up properly with public RDNS records. Many mail servers reject mail that comes from a domain without the appropriate RDNS configuration.
User checklist for "non delivered messages"
Checked Junk/Spam folder in the receiving mailbox.
Check sender mailbox for bounce (delivery problem report) mail messages.
You may receive first "warning email" after a few hours (e.g. 4h) of failing delivery attempts.
Some botched anti-spam system throw away messages "classified as spam" without any hint to the sender or the recipient -> ask admin/postmaster of the receiving mail server

Why does email need an envelope, and what does the "envelope" mean?

What is the exact difference between the envelope and the email in smtp?
Why does the protocol need the envelope? In snail mail, the letter needs not contain addresses and is not visible to the postman (at least that's what you want to believe), so all the routing is made entirely based on the envelope and that is clear to me.
However in e-mail, the letter itself is parseable and has headers such as From: and To:. Why is that not enough to route email? Why do we need an envelope?
And what is the meaning of a divergence between the envelope and the email itself? Does it necessarily mean that someone is trying to game the system, or is it, under certain circumstances (what circumstances?), legal to have a difference between them.
Your clarifications are more than welcome.
Puzzled email receiver.
The recipient address in the SMTP RCPT TO: command is what mail transports use to determine the actual recipient of an email. The addresses in the To: and Cc: headers are there for mail readers to display to users who the recipients are, but they're not actually used by mail transports.
Most mail clients set the same addresses in SMTP RCPT TO: and MAIL FROM: commands that they insert in To:, Cc:, and From: headers, so the "envelope" addresses will be the same as the addresses in the headers.
Envelope and header addresses will usually agree for most legitimate mail. Notable exceptions are Bcc: addresses and mailing lists.
Spammers often forge header addresses to try to avoid spam filters.
The bottom line is that the overhead would be too great. When mail servers are processing millions of messages per day, it's much faster during the SMTP session (The Envelope) when the mail server can process individual commands.
If you didn't use an Envelope, you would have to push the entire message at the SMTP server, before you could find out if the message needs to be rejected. Some messages are quite large (I've seen 100+Meg messages working with GIS images).
By using an Envelope, we can issue specific 1 line commands against the mail server, and the mail server will tell us if we are successful or not, right then and there.
The envelope is used by the SMTP server and the message headers are used by a mail reader as everyone else has said.
What has not been said is that the RCPT TO: is used to route the message to a specific user regardless of where the user's name appears in the headers. The user does not necessarily need to appear in the To: or even the Cc: headers. Think of a Bcc: where the only thing that the receiver knows is who the message was from. In this case, the To: and CC: headers should be empty - hence the blind part of BCC. In another case, if an email message has the user mentioned in the CC list along with 10 other users, how can the SMTP routing pick the appropriate user. The answer is that it uses the RCPT line to route the message.
This is also used when routing via mailing lists. The To: header will contain the mailing list e-mail address. An SMTP system will generate separate messages for each user in the list each with a specific RCPT TO: user#host... envelope. In this case, the user's name will not even appear in any of the other headers.
An email message is very similar to a physical letter that you would send in the mail. There is an envelope, with To/From information, and there is the actual letter on the inside, with it's own To/From information. The envelope to/from information is the real information that is used for message delivery, for both email servers and post offices.
When an envelope comes into a post office, they inspect the To address on the envelope, and send it to the correct destination. The post office workers have no knowledge of the letter inside the envelope. The letting inside could have completely different To/From information than the envelope says. The Envelope could say the message is to Bob, but the letter inside may say it's for Alice. Or in real world: The envelope could say the message is to SomeCompanyName, and when secretary open envelope, letter inside say, it's is for Mr. Brown which work in SomeCompanyName.
Source: Email Envelope vs Email Header

Resources