I have code here for a form that submits the data to receivers email. When I click the send this form button, it submits the email to receivers address. Following is the code that i'm using to send email

function send_mail_users($myname, $myemail, $contactname, $contactemail, $subject, $message)
{
	$headers .= "MIME-Version: 1.0\n";
	$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
	$headers .= "X-Priority: 3\n";
	$headers .= "X-MSMail-Priority: Normal\n";
	$headers .= "Return-Path: <".$myemail.">\n";
	$headers .= "X-Mailer: php\n";
	$headers .= "From: \"".$myname."\" <".mail@example.com.">\n";
	$headers .= "Reply-To: \"".$myname."\" <".$myemail.">\n";
	return(mail("\"".$contactname."\" <".$contactemail.">", $subject, $message, $headers, "-f$myemail"));
}

send_mail_users("senders_name", "senders@gmail.com", "receivers_name", "receivers@domain.com", "subject", "message");

in the above code i'm sending mail from my mail server "" to receivers mail address, with reply-to address as "". The email sent successful to receivers email address, but it's not working for auto generated emails from some email addresses.

Can any one help me regarding auto generated emails

Thank you in advance

Dani AI

Generated

Short answer: automatic replies and bounces go to the SMTP envelope sender (the MAIL FROM / Return-Path), not to the Reply-To header. That is why the auto-generated message from nodalofficer@airtel.in landed at mail@example.com instead of the user's address you put in Reply-To. (rfc-editor.org)

What to do (practical steps)

  • Ensure the envelope sender is the address you want auto-responses sent to. With PHP’s built-in mail() that means using the additional parameter (the sendmail “-f” envelope option) or an SMTP library that sets the envelope sender, not by adding a Return-Path: line to the header string. Many MTAs ignore a Return-Path header you manually add. (php.net)
  • If you cannot set the envelope sender on your host (shared hosts often rewrite or block -f), send via authenticated SMTP for the mailbox you want (or use a library such as PHPMailer and set its Sender/envelope value). That gives correct MAIL FROM handling. (phpmailer.github.io)

Cautions and alternatives

  • Do not blindly set the envelope to an arbitrary third-party address (for example a gmail address) from your server: SPF/DMARC checks and provider policies can cause rejection, rewriting, or deliverability problems. If you need reliable bounce handling, use a bounce mailbox on your sending domain (and forward/process bounces), or send through a verified outbound service that supports proper Return-Path/SPF/DKIM alignment. (rfc-editor.org)

Debug checklist

  • Send a test and inspect the raw headers (Return-Path / Received lines) to see what the recipient MTA actually recorded.
  • If auto-replies still go to the wrong place, try authenticated SMTP or a transactional provider and set the envelope sender there, or implement a domain-local bounce address and forward/handle replies programmatically.

This addresses the behavior you described in ’s post and answers ’s request for clarification about what “not working” means. (rfc-editor.org)

Recommended Answers

All 2 Replies

Please clarify what "...but it's not working for auto generated emails from some email addresses." means (with some examples of what works and what doesn't).

k, i'm sending mail to "" from "" with reply-to as "". "" sends auto generated mail to "", but i want that mail to be delivered to ""

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.