PHP邮件:电子邮件字段赢得';t打印

PHP邮件:电子邮件字段赢得';t打印,php,html,html-email,Php,Html,Html Email,这是我第一次使用PHP的邮件功能,它工作得很好,只是我似乎无法将用户的电子邮件地址打印到通过电子邮件发送回表单收件人的提交表单数据中 当前,当我获取表单数据时,看起来是这样的(如您所见,电子邮件字段为空): 这是我的表格代码: <form id="contact" action="process.php" method="post" role="form"> <!---snip to save space and show relevant code---> <l

这是我第一次使用PHP的邮件功能,它工作得很好,只是我似乎无法将用户的电子邮件地址打印到通过电子邮件发送回表单收件人的提交表单数据中

当前,当我获取表单数据时,看起来是这样的(如您所见,电子邮件字段为空):

这是我的表格代码:

<form id="contact" action="process.php" method="post" role="form">
<!---snip to save space and show relevant code--->
<label for="email">Email</label>
    <input type="email" name="email" id="email" class="form-control input-lg" tabindex="3">

电子邮件
My process.php代码:

<?php

$recipient = "johndoe@aol.com";
$subject = "FORM SUBMISSION";

$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$replyTo = $_POST['email'];
$sender = "From: $replyTo\r\n";
$message = $_POST['message'];
$whyContact = $_POST['whyContact'];

$sender = "MIME-Version: 1.0\n";
$sender = "Content-type: text/html; charset=us-ascii\n";

$msgBody = "
<html>
<head>
<title>title here</title>
</head>

<style type='text/css'>

body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;}
table td {border-collapse: collapse;}
table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }

</style>

<body>

<table cellpadding='0' cellspacing='0' border='0' style='width:100%;border-bottom:1px solid #eee;font-size:12px;line-height:135%;font-family:'Lucida Grande','Lucida Sans Unicode', Tahoma, sans-serif'>
<tr style='background-color:#F5F5F5'>
<th style='vertical-align:top;color:#222;text-align:left;padding:7px 9px 7px 9px;border-top:1px solid #eee;'>Name:</th>
<td style='vertical-align:top;color:#333;width:60%;padding:7px 9px 7px 0;border-top:1px solid #eee;'>$firstName $lastName</td>
</tr>
<tr style='background-color:#FFFFFF'>
<th style='vertical-align:top;color:#222;text-align:left;padding:7px 9px 7px 9px;border-top:1px solid #eee;'>Email:</th>
<td style='vertical-align:top;color:#333;width:60%;padding:7px 9px 7px 0;border-top:1px solid #eee;'>$replyTo</td>
</tr>
<tr style='background-color:#F5F5F5'>
<th style='vertical-align:top;color:#222;text-align:left;padding:7px 9px 7px 9px;border-top:1px solid #eee;'>What are you contacting us about?</th>
<td style='vertical-align:top;color:#333;width:60%;padding:7px 9px 7px 0;border-top:1px solid #eee;'>$whyContact</td>
</tr>
<tr style='background-color:#FFFFFF'>
<th style='vertical-align:top;color:#222;text-align:left;padding:7px 9px 7px 9px;border-top:1px solid #eee;'>Message:</th>
<td style='vertical-align:top;color:#333;width:60%;padding:7px 9px 7px 0;border-top:1px solid #eee;'>$message</td>
</tr>
</table>
</body>
</html>
";

mail($recipient, $subject, $msgBody, $sender);
?>

您正在用每个分配覆盖
$sender
,这意味着您的
From
MIME版本
标题将被删除。尝试以下方法:

$sender  = "From: $replyTo\r\n";
$sender .= "MIME-Version: 1.0\n";
$sender .= "Content-type: text/html; charset=us-ascii\n";

我想出来了。在我的示例中,我忘记将“.”添加到两个$sender变量中。谢谢

谢谢,艾米丽。不幸的是,这并没有带来什么不同:(