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);

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!