Forum Moderators: coopster

Message Too Old, No Replies

PHP form reply address

         

annejan

8:23 pm on Jul 22, 2004 (gmt 0)

10+ Year Member



Hello everybody,

As a total newbie with PHP, I desperatly need your help! I have a PHP form mailer wich works great, exept for one thing. In outlook I can't do a reply on the mail, because it doesn't show the sender. I do use $email, but ... : (
Please help, for I have no hairs left!

Here's my script:

<?php

//change this address to where you want the results of the form sent to
$sendto = "myemail@domain.com";
//or comment(//) out the above line and uncomment line below to send the recipient email from the HTML form
//$sendto = $_POST{"to"};

//DO NOT CHANGE ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
$sendit = "1";
$today = date("j/m/Y, H:m");
$uemail = $_POST["email"];
$sitename = $_SERVER["HTTP_HOST"];
$redirectURL = "http://www.mydomain.com/html/thankyou.htm";

//check to see if posted
if (! $_POST ¦¦! $HTTP_POST_VARS) {
//if not posted display error page
echo "<html><head><title>Error</title></head><body>";
echo "<h4>Uw aanvraag is niet verstuurd, ga terug en probeer nogmaals.</h4>";
echo "</body></html>";
}else{

//error function for invalid email address
function error( $error )
{
echo "<html><head><title>Error</title></head><body>";
echo "<div align=center><h4>Error: $error</h4>\n";
echo "</div>\n";
echo "</body></html>";
exit;
}
//check email address
if( $uemail == "" ) error( "email adres verplicht!" );
elseif(!eregi( "^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$", $uemail ) )
error( "ongeldig email adres!" );

//compose the email
if( $sendit == "1" )
{
$header = "MIME-Version: 1.0\r\n";
$header .= "From: $uemail\r\n";
$header .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$subject = "Aanvraag informatie $sitename.";
$body = "Aanvraag verzonden door " . $_POST{"email"} . " op $today \n";
//split the contents of POST
foreach ($_POST as $posted_name => $posted_value) {
$body .= "$posted_name: $posted_value \n";
}//end foreach
@mail( $sendto, $subject, $body, $header );
}//close mail function

// check if thanks page specified
if (! $_POST{"thankyou"}) {
//page displayed if no thanks page specified
header("Location: ".$redirectURL);
}else{
//extract the thanks page from form post
header("Location: ".$redirectURL);
exit;
}//close check thanks page
}//close check post
?>

Thanks in advance.

RussellC

10:29 pm on Jul 22, 2004 (gmt 0)

10+ Year Member



use $_POST['email'] instead of $_POST{"email"}

jatar_k

11:06 pm on Jul 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld annejan,

RussellC is right but you have already assigned the $_POST['email'] to a var earlier in the script.

$uemail = $_POST["email"];

So just change the line to use $uemail. You could also set the Reply-to in the header.

$header = "MIME-Version: 1.0\r\n";
$header .= "From: $uemail\r\n";
$header .= "Reply-To: $uemail\r\n"
$header .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$subject = "Aanvraag informatie $sitename.";
$body = "Aanvraag verzonden door $uemail op $today \n";

that should set the reply to for the email to the posted email address.

annejan

6:37 am on Jul 23, 2004 (gmt 0)

10+ Year Member



Thank you guys, for your input.
I'm afraid though, it isn't gonna work.

But ... I will try before I start wining about it.

I'll let you now.

Thanks : )

annejan

3:02 pm on Jul 23, 2004 (gmt 0)

10+ Year Member



Cheers guys, but it didn't help.
I think it has something to do with the server.
Because I tried it on another server, with good result. Any ideas?

Thanks again.

jatar_k

4:16 pm on Jul 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what kind of server is it not working on?
could also be the email server that is delivering the mail. Try looking at the full headers of the message you receive also.

annejan

5:12 pm on Jul 23, 2004 (gmt 0)

10+ Year Member



Thanks Jatar,

but can you tell me specific what to look for.

Thanks

annejan

7:12 am on Jul 24, 2004 (gmt 0)

10+ Year Member



Well, I looked at the headers, but didn't see anything special about it.
The original From is another adres (of the server),
but it's overwritten with the variable.
The server is using Qmail, anything special with that?

Thanks in advance (again),

Kind regards,
Anne Jan

annejan

8:16 am on Jul 24, 2004 (gmt 0)

10+ Year Member



Ok, I finally found out what's cuasing the problem!
M$ Outlook doesn't show the reply address, but
the webmail client does.
So I think I have to move to another MBoard?
Or does anyone have an idea?

Gr,
Anne Jan

annejan

8:47 am on Jul 24, 2004 (gmt 0)

10+ Year Member



This is the headerinformation found in outlook:

Return-Path: <root@mail01.example.nl>
Delivered-To: annejan@E
Received: (qmail 9050 invoked from network); 24 Jul 2004 08:10:38 -0000
Received: from web06.example.nl (62.xx.xx.xx)
by mail01.example.nl with QMQP; 24 Jul 2004 08:10:38 -0000
Date: 24 Jul 2004 08:10:45 -0000
Message-ID: <20040724081045.19186.qmail@web06.example.nl>
To: annejan@example.nl
Subject: Aanvraag informatie www.example.nl.
MIME-Version: 1.0

[edited by: jatar_k at 4:38 pm (utc) on July 24, 2004]
[edit reason] generalized [/edit]

annejan

8:57 am on Jul 24, 2004 (gmt 0)

10+ Year Member



Jippy! : )
Solved the problem!

Just removed the dot.

$header .= "From: $uemail\r\n";

to

$header = "From: $uemail\r\n";

Thanks anyway!

sonjay

12:19 pm on Jul 24, 2004 (gmt 0)

10+ Year Member



Okay, what's that dot for then? Why would you put it there, if the $header doesn't work without it, and what causes the $header to work or not work depending on the existence of the dot?

jatar_k

4:45 pm on Jul 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



does that mean you have this now?

$header = "MIME-Version: 1.0\r\n";
$header = "From: $uemail\r\n";
$header .= "Reply-To: $uemail\r\n"
$header .= "Content-type: text/plain; charset=iso-8859-1\r\n";

that would mean that the MIME header is getting overwritten and not being sent. That would make me assume that the MIME was giving you a problem.

I have had problems with the order in which i have sent the headers and MIME was giving the issues.

annejan

6:35 pm on Jul 24, 2004 (gmt 0)

10+ Year Member



That's exactly what I have now!
And it works perfect (in outlook and webmail).
I think outlook had a problem with it, because webmail gave me the right reply address.

I'm not a script genius, but I'm fine with how it works now : )

Gr,
Anne Jan