[英]PHP mail: Email field won't print
這是我第一次使用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);
?>
您使用每個分配覆蓋$sender
,這意味着您的From
和MIME-Version
標頭被刪除。 試試像:
$sender = "From: $replyTo\r\n";
$sender .= "MIME-Version: 1.0\n";
$sender .= "Content-type: text/html; charset=us-ascii\n";
我想到了。 我忘了添加“。” 我的例子中的兩個$ sender變量。 謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.