How to Fix “On behalf of” in from field of email

While using php mail for newsletter or for any other emails, We see “On behalf of” in the from field. This issue mostly comes in Outlook or gmail like below.

on-behalf-of

How to fix “On Behalf of” in from field for Outlook or gmail.

The reason for this is email authentication, which is a way for email recipients to verify that an email was sent by who it claims to be from.

Email clients like Outlook and Gmail then display this extra information to help recipients determine which emails are legitimate.

To fix this issue, We need to change “Sender” header information for the same as From header. like below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
// setup MIME and Content-type
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
$headers .= 'From: Example Name <example-email@domain.com>' . "\r\n";
//setup sender header as well
$headers .= 'Sender: Example Name <example-email@domain.com>' . "\r\n";
//setup return path, to get mail delivery notification failure on specific address
$headers .= 'Return-path: Example Name <example-email@domain.com>' . "\r\n";
//specify Reply to address as well
$headers .= 'Reply-To: Example Name <example-email@domain.com>' . "\r\n";
 
$to="delivery-email@domain.com";
$subject ="Test Email subject";
$message="email message";
// Mail it
mail($to, $subject, $message, $headers);
?>

In this way we can fix “On behalf of” issue for email. For more updates stay tuned…

Leave a Reply

Your email address will not be published. Required fields are marked *


*