June 24, 2013
PHP: sending email with my website domain
Abdullah Salma’s Question:
When I used mail()
function and sent an email to my self from my website. I recived the email from myusername@pickens.dreamhost.com
I want to change the sender into noreply@mydomain.com
but is there a way ?
You can change the sender by using headers while sending your email. Such basic things are well illustrated on the PHP manual page of mail()
This is an example taken from that manual page
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "rn" .
// ^ This is where you update your header to show the sender
'Reply-To: webmaster@example.com' . "rn" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);