这是我第一次使用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">
我的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);
?>
答案 0 :(得分:1)
您对每个分配覆盖$sender
,这意味着您的From
和MIME-Version
标头被删除。尝试类似的事情:
$sender = "From: $replyTo\r\n";
$sender .= "MIME-Version: 1.0\n";
$sender .= "Content-type: text/html; charset=us-ascii\n";
答案 1 :(得分:1)
我明白了。我忘了添加“。”我的例子中的两个$ sender变量。谢谢!