我正在尝试从表单中获取输入并将结果通过电子邮件发送给我。我想将电子邮件的格式设置为与客户在填写表格时看到的相同(或非常相似)我在尝试完成此操作时遇到了困难。任何帮助将不胜感激。
这是我的表单数据
<form id="ContactKathryn" name="ContactKathryn" method="post" action="sendform/sendtokathryn.php">
<table width="60%" border="0" cellpadding="2px" style="position:relative; left:20%">
<tr>
<td width="25%" align="right">Name:</td>
<td width="75%" align="left"><input name="ContactName" type="text" size="40" maxlength="100" /></td>
</tr>
<tr>
<td align="right">Email Address:</td>
<td align="left"><span id="sprytextfield1">
<input name="EmailAddress" type="text" id="EmailAddress" size="40" maxlength="150" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td align="right">Phone Number:</td>
<td align="left"><span id="sprytextfield2">
<label for="PhoneNumber"></label>
<input name="PhoneNumber" type="text" id="PhoneNumber" maxlength="15" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td align="right">Practice Name:</td>
<td align="left"><input name="PracticeName" type="text" size="40" maxlength="100" /></td>
</tr>
<tr>
<td align="right">Message:</td>
<td align="left"><textarea name="Message" cols="40" rows="10"> </textarea></td>
</tr>
<tr>
<td align="center" width="25%"></td>
<td align="center" width="75%"><input name="SubmitForm" type="submit" id="SubmitForm" onclick="MM_popupMsg('Are you sure you would like to submit this form?\r');return document.MM_returnValue" value="Submit Form" /><input type="reset" name="ResetForm" id="ResetForm" value="Reset Form" /></td>
</table>
</form>
这是我的 PHP 代码:
<?php
// Where to redirect after form is processed.
$url = 'http://www.mydomain.com';
// multiple recipients
$to = '123456@gmail.com'; // note the comma
// subject
$subject = 'Someone sent you a contact request';
// message
$message = '<html><body> ';
$message = 'MIME-Version: 1.0' . "\r\n";
$message = 'Content-type: text/html; charset=iso-8859-1';
$message = ' <p>Kathryn, someone sent you an email from the website</p>';
$message = ' <table>';
$message = ' <tr><td>Name:</td><td>'%$ContactName%'</td></tr>';
$message = ' <tr><td align="right">Email Address:</td><td align="left">'%$EmailAddress%'</td></tr>';
$message = ' <tr><td align="right">Phone Number:</td><td align="left">'%$PhoneNumber%'</td></tr>';
$message = ' <tr><td align="right">Practice Name:</td><td align="left">'%$PracticeName%'</td></tr>';
$message = ' <tr><td align="right">Message:</td><td align="left">'%$Message%'</textarea></td></tr>';
$message = ' </table></body></html>';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $subject, $message, 'From: '.$EmailAddress.'', $headers);
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'
?>
当有人提交此表单时,我在电子邮件中收到的唯一内容是:
</table></body></html>