douju5062
douju5062
2013-08-19 18:08
浏览 45
已采纳

Reply-To标题没有选择php变量

I am creating a page that sends the response from contact form within mail but reply-to is not working (the variable i am using is having value, but is not added within headers)

here's my code:

<?php

//$uname=$_REQUEST['uname'];
if(isset($_REQUEST['name']))
{
    $name=$_REQUEST['name'];
}

if(isset($_REQUEST['email']))
{
    $email=$_REQUEST['email'];
}   

if(isset($_REQUEST['phone']))
{
    $phone=$_REQUEST['phone'];
}

if(isset($_REQUEST['message']))
{
    $message=$_REQUEST['message'];
}

// TESTING IF VARIABLES HAVE VALUES
echo "$name $email $phone $message";
// RESULT: TRUE TILL HERE


if($name=="" || $email=="" || $phone=="" || $message=="")
{
    header("location:../?inst=invalid");    
}
else
{

    // ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to="mail@example.com";

// Your subject
$subject="$name Contacted you via Contact Form";

// From
$headers  = "From: ME <no-reply@example.com>
";
$headers .= 'Reply-To:' . $email . "
";
$headers .= "Return-Path: info@example.com
";
$headers .= "X-Mailer: PHP
";
$headers .= 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
"; 

print $message;
// send email
$sentmail = mail($to,$subject,$message,$headers);
//$sentmail = mail($to1,$subject,$message,$header);
}

// if your email succesfully sent
if($sentmail){
echo "Mail Sent.";
}
else {
    header("location:../landing/?status=verification-pending");
    }

?>

Now when i checked headers in my gmail, the value for $email doesn't appear in header information, Also no message is received. All I get is a blank message or may be $message is not printing anything like the same case i am facing with reply-to.

please help me a little with this. Thanks in advance.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyaju4259
    douyaju4259 2013-08-19 18:49
    已采纳

    Actually there was a little mistake with the above code. I mistakenly added = instead of == while comparison.

    This line:

    if($name=="" || $email="" || $phone="" || $message="")
    

    Should read as:

    if($name=="" || $email=="" || $phone=="" || $message=="")
    

    Since = is for equation and not a condition for comparison ==

    Fixed it in the Question

    点赞 评论
  • douyinlai2169
    douyinlai2169 2013-08-19 18:32

    Check that you have php warnings and notices enabled. When you are echoing out $name, $email, etc you are doing a redirect using headers after that. If your php notices etc aren't turned on, your header redirect will fail due to having already echoed something, and you won't know that you had invalid input. This is part of the reason you shouldn't echo things out during logic, but should store and out put values later.

    点赞 评论

相关推荐