Reply to email problem

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
pendleton
Forum Newbie
Posts: 4
Joined: Tue May 06, 2008 11:33 am

Reply to email problem

Post by pendleton »

Hi there,
I've just built a contact form in my Flash website and have now got it working ok with my php script. The only problem is when I recieve an email from the form, the name that appears in my inbox is my hosting username and domain address. Is there anyway I can get the senders name or email address to appear there instead? Also when I hit reply to the email the reply address in the new email is my hosting address again! Can my script be altered so that I can reply to the sender's address without having to enter it in manually?
I know these are probably straight forward things to fix but I'm very new to PHP and am totally stumped!
Many thanks.

Code: Select all

<?php
 
//receiving variables from Flash, through REQUEST object, and storing them in local php variables
$title    = $_REQUEST["title"];
$firstname    = $_REQUEST["firstname"];
$surname    = $_REQUEST["surname"];
$email   = $_REQUEST["email"];
$phone    = $_REQUEST["phone"];
$message = $_REQUEST["message"];
 
//filling information for email to be sent
$to       = "me@myemail.com";   //destination email
$subject  = "Website contact form"; //email subject
$full_msg = "Title: " . $title . "\n Firstname: " . $firstname . "\n Surname: " . $surname . "\n Email: " . $email . "\n Phone: " .  $phone .  "\n Message: " . $message;   //email body
 
//line that actually sends an email
$ok= mail($to, $subject, $full_msg);
 
//based on results of mail function, sending failure or success message back to Flash
if($ok) { 
    echo("&serverResponse=Message was successfully sent."); 
} else { 
    echo("&serverResponse=Sorry but the message could not be sent. Please try again.");
} 
?>
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Reply to email problem

Post by andym01480 »

Code: Select all

 
//line that actually sends an email
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
 
$ok= mail($to, $subject, $full_msg,$headers);
 
pendleton
Forum Newbie
Posts: 4
Joined: Tue May 06, 2008 11:33 am

Re: Reply to email problem

Post by pendleton »

Hey thanks Andym I'll give it a go!
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Reply to email problem

Post by andym01480 »

No problems - I copied it from the manual - you can download it from http://www.php.net
Your the third person this month asking the same question!!!
pendleton
Forum Newbie
Posts: 4
Joined: Tue May 06, 2008 11:33 am

Re: Reply to email problem

Post by pendleton »

Hello again,
I've nearly got my script working ok with my form now, the only problem is I still seem to get my hosting domain tagged onto the name of the sender I get in my inbox. For example if I put in Pendleton as the name in my form, when I recieve the email the name header reads: Pendleton@myhost103.mesa1.secureserver.net, even though in my script I have only declared $name in my $headers = 'From: ' statement? Is there anything I do so that just the senders name appears?
Thanks again.

Code: Select all

<?php
 
//receiving variables from Flash, through REQUEST object, and storing them in local php variables
$title    = $_REQUEST["title"];
$firstname    = $_REQUEST["firstname"];
$surname    = $_REQUEST["surname"];
$email   = $_REQUEST["email"];
$phone    = $_REQUEST["phone"];
$message = $_REQUEST["message"];
 
//filling information for email to be sent
$to       = "russ@kirby15.wanadoo.co.uk";   //destination email - CHANTE YOUR EMAIL HERE
$subject  = "Website contact form"; //email subject
$full_msg = "Title: " . $title . "\n Firstname: " . $firstname . "\n Surname: " . $surname . "\n Email: " . $email 
 
. "\n Phone: " .  $phone .  "\n Message: " . $message;  //email body
 
//line that actually sends an email
$headers = 'From: ' . $name . "\r\n" .
   'Reply-To: ' . $email . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
 
$ok= mail($to, $subject, $full_msg,$headers);
 
//based on results of mail function, sending failure or success message back to Flash
if($ok) { 
    echo("&serverResponse=Message was successfully sent."); 
} else { 
    echo("&serverResponse=Sorry but the message could not be sent. Please try again.");
} 
?>
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: Reply to email problem

Post by EverLearning »

That's probably because $name contains persons name e.g. "John Smith". Use something like this

Code: Select all

$headers .= "From: ".$fromname."<".$fromaddress.">\r\n";
where

Code: Select all

$fromname = "John Smith";
$fromaddress = "john.smith@gmail.com";
pendleton
Forum Newbie
Posts: 4
Joined: Tue May 06, 2008 11:33 am

Re: Reply to email problem

Post by pendleton »

Thanks EverLearning that has fixed my problem!
Post Reply