Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the name of an email sender via PHP

Tags:

php

email

So I want the from field when an email is opened to be something like

"Jack Sparrow Via somesite" as opposed to an explicit email address.

I wondering how to set this in PHP's mail() function?

like image 773
algorithmicCoder Avatar asked Feb 28 '12 18:02

algorithmicCoder


1 Answers

You can accomplish this by using basic headers.

<?php
$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: Jack Sparrow <[email protected]>' . PHP_EOL .
    'Reply-To: Jack Sparrow <[email protected]>' . PHP_EOL .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>
like image 163
enderskill Avatar answered Oct 05 '22 23:10

enderskill