Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the Return-Path in PHP mail function

Tags:

php

email

Is it possible to change the Return-Path value in emails are sending via mail() function of PHP ?

It's value is '[email protected]' in emails I send in my site and it causes some problems on email delivery failed process. I want to set it to my email address.

Here's the code I have tried:

$headers = 'MIME-Version: 1.0' . "\n"; $headers .= "Content-type: text/html; charset=utf-8" . "\n"; $headers .= "Return-Path: <[email protected]>"."\n"; $headers .= "Errors-To: <[email protected]>"."\n"; // Additional headers $headers .= "To: [email protected] <[email protected]>" . "\n"; $headers .= "From: [email protected] <[email protected]>"; // Mail it mail('[email protected]', 'test', 'salam', $headers, "f"); 
like image 917
hd. Avatar asked Sep 16 '12 10:09

hd.


People also ask

How do I change my return-path?

Changing the Return-Path Header on Your Training EmailsClick your email address on the top-right of the screen, then click Account Settings. Navigate to the Training Settings section. Under the Training Email Headers subsection, click the checkbox next to Overwrite Fixed Return-path Address with Sender Address.

What does PHP mail function return?

Return Value: Returns the hash value of the address parameter, or FALSE on failure. Note: Keep in mind that even if the email was accepted for delivery, it does NOT mean the email is actually sent and received!

What is return-path in SMTP?

The return-path is used to process bounces from your emails and is set in the email header. It defines how and where bounced emails will be processed. The return-path can also be referred to as a bounce address or a reverse path, and is an SMTP address that is separate from your sending address.

What is the mail () function in PHP?

PHP mail() function is used to send email in PHP. You can send text message, html message and attachment with message using PHP mail() function.


1 Answers

You can set reply to & return path into headers as below

$headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'Return-Path: [email protected]' 

OR as the fifth parameter to adjust the return path

mail($to, $subject, $message, $headers, "-f [email protected]"); 

where [email protected] should be replaced by your mail.

like image 115
GBD Avatar answered Sep 19 '22 17:09

GBD