Knowledgebase
Knowledgebase
Setting FROM name and address in PHP Emails
Posted by Will Kruss on 17 May 2020 09:33 AM

If you are using PHPs mail function to send mail and would like to set not only the FROM email address, but also the name of the sender, please use the instructions below:

By default, PHP will send e-mail from the account you are running the script from. Usually this is in the format of:

username@server.hostname

To ensure the From: address displays correctly to your users, please ensure you are sending the return-path, reply-to and from headers with the mail() function. Please be advised we do NOT support this code, it was obtained from the PHP documentation. The code shown here is an illustration of correct header configuration:

$to = "recipient@somedomain.com";

$subject = "Testing From Address";

$message = "This is a test, please disregard.";

$headers .= 'From: Your Name <test@yourdomain.com>' . "\r\n";

$headers .= 'Reply-To: test@yourdomain.com' ."\r\n";

mail($to, $subject, $message, $headers);

 

 

(0 vote(s))
Helpful
Not helpful