我对PHP很陌生,所以我不确定我在这里做错了什么。我可以让它发送电子邮件,但它出现“未知发件人”,没有消息。我究竟做错了什么?请帮忙!
<?
$userFirstName = $_GET["txtFirstName"];
$userLastName = $_GET["txtLastName"];
$userEmail = $_GET["txtEmail"];
$userPhone = $_GET["txtPhone"];
$userComment = $_GET["txtComment"];
$to = "arandomEmail@gmail.com";
$subject = "From randomURL.com";
$email = $_REQUEST['email'] ;
$message = $_REQUEST["This message is from " .$userFirstName. " " .$userLastName. ".\n
Their phone number is " .$userPhone. " and has this comment/question: \n" .$userComment. "."] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent) {
print("Your mail was sent successfully");
}
else {
print "We encountered an error sending your mail";
}
?>
答案 0 :(得分:1)
消息不应该来自$ _REQUEST
$message = "This message is from " .$userFirstName. " " .$userLastName. ".\n
Their phone number is " .$userPhone. " and has this comment/question: \n".$userComment. ".";
同时检查您是否实际通过$ _REQUEST中的电子邮件提供脚本。这里的假设是你使用POST或GET来引入它。您可以使用
检查$ _REQUEST中的内容print_r($_REQUEST);