Forum Moderators: coopster
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 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.
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]
$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.