Start a conversation

How do I change the Return-Path using the PHP mail () function?

If the site uses the mail () php function, then we will consider how it is possible to change the default user email login @ server to one of those created on the domain.

In PHP, the mail () function has the following syntax:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

The 5th parameter allows you to specify arguments for invoking the sendmail command, for example, the "-f" switch.

Thus, if, for example, you want to send a letter with additional headers and with the Return-Path you need, then you can use the following code:
<?php

mail("email@yourdomain", "subj", "message text", "From: email@yourdomain\nContent-Type: text/plain; charset=windows-1251\nContent-Transfer-Encoding: 8bit", "-femail@yourdomain");

?>
If additional email headers are not required, use null in the 4th parameter:
<?php

mail("email@yourdomain", "subj", "message text", null, "-femail@yourdomain");

?>

Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Alexey Momot

  2. Posted
  3. Updated

Comments