"Reply-To:" not functioning

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
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

"Reply-To:" not functioning

Post by Leao »

Hi,

I've set-up an email form that sends variables to the attached PHP script. The message is sent OK. The only problem is the "Reply-To" feature. When I click Reply in my email account on receipt of a message sent via the form the address in the 'Reply' field of my email is X-Mailer: PHP/4.3.11@linhost199.prod.mesa1.secureserver.net rather than the email address contained in the $yourname variable.

Any ideas about what I'm doing wrong? I've tried swapping the order of the headers around a bit but it doesn't seem to solve the problem.

Many, many thanks,

leo

Code: Select all

<?

$to = 'myname@mydomain.org';

$subject = 'St. Patrick\'s message';

$body = "You have received a message via the St. Patrick's website. The details of the message are listed below...\n\nName: $yourname\nEmail: $youremail\nMessage: $yourmessage";

$body = wordwrap($body, 70);

$headers = "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: myname@mydomain.org\r\n"; 
$headers .= "Return-Path: myname@mydomain.org\r\n";
$headers .= "Reply-To: $youremail";
$headers .= 'X-Mailer: PHP/' . phpversion()."\r\n";

mail($to, $subject, $body, $headers, "-fmyname@mydomain.org");

?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

there's a \r\n after every header except Reply-To
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Post by Leao »

I modified it to add the \r\n (see below) but the same prob still persisted. Any other ideas?

Cheers

leo

Code: Select all

<?

$to = 'myname@mydomain.org';

$subject = 'St. Patrick\'s message';

$body = "You have received a message via the St. Patrick's website. The details of the message are listed below...\n\nName: $yourname\nEmail: $youremail\nMessage: $yourmessage";

$body = wordwrap($body, 70);

$headers = "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: myname@mydomain.org\r\n";
$headers .= "Return-Path: myname@mydomain.org\r\n";
$headers .= "Reply-To: $youremail\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion()."\r\n";

mail($to, $subject, $body, $headers, "-fmyname@mydomain.org");

?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Where are you setting the vars that are inside the body of the script? Have you echoed those out to make sure they contain data?
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Post by Leao »

Everah wrote:Where are you setting the vars that are inside the body of the script? Have you echoed those out to make sure they contain data?
Hi,

I'm setting the variables in a form in a Flash .swf file. It works - when someone uses the form I receive an email with all the variables completed. The only problem is the 'Reply-To' element of the PHP script that doesn't seem to work. As I said, when I receive an email via the form and click Reply the Reply-To address is X-Mailer: PHP/4.3.11@linhost199.prod.mesa1.secureserver.net rather than the email address contained in the $yourname variable.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Do not use mail() but echo $headers. Does it print the expected data?

Code: Select all

<?php
$to = 'myname@mydomain.org';

$subject = 'St. Patrick\'s message';

$body = "You have received a message via the St. Patrick's website. The details of the message are listed below...\n\nName: $yourname\nEmail: $youremail\nMessage: $yourmessage";

$body = wordwrap($body, 70);

$headers = "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: myname@mydomain.org\r\n";
$headers .= "Return-Path: myname@mydomain.org\r\n";
$headers .= "Reply-To: $youremail\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion()."\r\n";


echo '<pre>', htmlentities("mail($to, $subject, $body, $headers, \"-fmyname@mydomain.org\");"), "</pre>\n";
?>
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Post by Leao »

I got it to work with the following script.

Cheers

Code: Select all

<?
$to = 'mail@mydomain.org';

$subject = 'St. Patrick\'s message';

$body = "You have received a message via the St. Patrick's website. The details of the message are listed below...\n\nName: $yourname\nEmail: $youremail\nMessage: $yourmessage";

$body = wordwrap($body, 70);

$headers = "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: mail@mydomain.org\r\n";
$headers .= "Return-Path:mail@mydomain.org\r\n";
$headers .= "Reply-To: $youremail\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion()."\r\n";

mail($to, $subject, $body, $headers, "-fmail@mydomain.org.org");
?>
Post Reply