Jump to content

Recommended Posts

I am using the below (very simple) code to process a contact form.  However, I cannot figure out how to have the email say it is from the user's email address.  The address is entered in the form in a field called "email".  What do I need to add to resolve this issue?

 

<?PHP

 

$to = "[email protected]";

$subject = "xyz";

$headers = "";

$forward = 1;

$location = "http://www.fghijk.com/";

$date = date ("l, F jS, Y");

$time = date ("h:i A");

 

$msg = "Below is your request confirmation. It was submitted on $date at $time.\n\n";

 

if ($_SERVER['REQUEST_METHOD'] == "POST") {

    foreach ($_POST as $key => $value) {

        $msg .= ucfirst ($key) ." : ". $value . "\n";

    }

}

else {

    foreach ($_GET as $key => $value) {

        $msg .= ucfirst ($key) ." : ". $value . "\n";

    }

}

 

mail($to, $subject, $msg, $headers);

if ($forward == 1) {

    header ("Location:$location");

}

else {

    echo "Thank you for subscribing to our newsletter. We will add you to our mailing list as soon as possible.";

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/119464-question-about-simple-mailer-script/
Share on other sites

$headers should look somethink like this:

 

		$headers="From: ".$yourname." <".$youremail.">\n";
	$headers.="Reply-To: ".$yourname." <".$youremail.">\n";
	$headers.="MIME-Version: 1.0\n";
	$headers.="Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
	$headers.="X-Sender: ".$_SERVER['REMOTE_ADDR']."\n";
	$headers.="X-Mailer: PHP/".phpversion()."\n";
	$headers.="X-Priority: ".$priority."\n"; 
	$headers.="Return-Path: <".$youremail.">\n";
	$headers.="This is a multi-part message in MIME format.\n";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.