How to add sender name in php mail functrion
To add a sender name in the PHP mail function, you can use the From
header and specify the sender's name and email address.
Here is an example:
$headers = 'From: Your Name <[email protected]>'. "\r\n";
mail('[email protected]', 'Subject', 'Message', $headers);
In this example, Your Name
is the sender's name and [email protected]
is the sender's email address.
You can also use the additional_headers
parameter of the mail
function to specify the From
header:
mail('[email protected]', 'Subject', 'Message', null, 'From: Your Name <[email protected]>');
Make sure to replace Your Name
and [email protected]
with the actual sender's name and email address.
Note that the From
header should be in the format Name <[email protected]>
. The Name
part is the sender's name, and the [email protected]
part is the sender's email address.
Also, keep in mind that the From
header is used to specify the sender's email address and name, but it does not guarantee that the email will be sent from that address. The email server may still use a different sender address or name.