PHP Mail From Name

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aalbright
Forum Newbie
Posts: 6
Joined: Sun Feb 15, 2009 8:32 pm

PHP Mail From Name

Post by aalbright »

I'm using this code in a feedback form on a website:

Code: Select all

<?php
$to = "you@yoursite.com";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?>
Is it possible to add a from name to the email that is sent? The from name on the email would be "Contact form" or something, instead of the email the email address given. This would help to identify emails as ones from the contact form.

Thanks!
sparrrow
Forum Commoner
Posts: 81
Joined: Mon Oct 20, 2008 12:22 pm

Re: PHP Mail From Name

Post by sparrrow »

Code: Select all

$from = "John Smith <john.smith@devnetwork.net>";
Post Reply