I have a commercial system that will send emails to customers "from" the agent who added them.
When new agent is added, agent@domain.com is automatically created. So I want my email to be from CompanyName - Agent mail. This is how I tried to handle this:
$headers = "From:".$companyname." ".$Agentmail."\r\n";
$headers = "Reply-To:".$Agentmail."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
However, I get emails from "user"(user@servername) while reply-to
is correct, as listed above. If I remove reply-to
, it works perfect, e-mails in inbox will be shown as from CompanyName, and when opened, it will be CompanyName (Agentmail), however, such emails don't get sent to @hotmail addresses, which is a huge issue.
Before you suggest that I completely switch my mail method to something along the lines of PHPMailer, please consider the way I use to send e-mails below, it may not be compliant with your suggestion. Thank you!
Full e-mail code:
ob_start();
include("./email/mailtemplate.php");
$message = ob_get_clean();
$body = strtr($content, $replaceWord);
$headers = "From:".$companyname." ".$Agentmail."\r\n";
$headers = "Reply-To:".$Agentmail."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($email, $subject, $message, $headers);
I echo $body
inside mailtemplate.php, as it requires some parsing etc. Mailtemplate.php is simply html email template.
Thanks