PHP 表单电子邮件请求不通过表单数据

标签 php html forms email

我一直在研究一个 php 脚本和一个 html 表单(都在单独的文件中),它们从表单中获取数据并将其通过电子邮件发送给我。我很难让用户填写的表单数据通过电子邮件发送。 我希望电子邮件包含用户的电子邮件作为电子邮件中的发件人。

谁能帮我弄清楚这些文件有什么问题?

HTML 格式:

<form id="ContactUs" name="ContactUs" method="post" action="sendform/sendform.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">&nbsp;</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>

名为 sendform.php 的单独 PHP 文件

<?php
// Where to redirect after form is processed. 
$url = 'ThankYou.php';


// multiple recipients
$to  = 'T@domain.com'; 

// subject
$subject = 'Someone sent you a contact request';

$headers = 'From: '.$EmailAddress.'/r/n';
$headers .= 'MIME-Version: 1.0\r\n';
$headers .= 'Content-Type: text/html; charshet=ISO-8859-1\r\n';






// message
$messagetext = '<html><body>';
$messagetext .= '  <p>Website Form Submit</p>';
$messagetext .= '    <table>';
$messagetext .= '        <tr><td align="right">Name:</td><td>'; $_GET[$ContactName] .'</td></tr>';
$messagetext .= '        <tr><td align="right">Email Address:</td><td align="left">'; $EmailAddress .'</td></tr>';
$messagetext .= '        <tr><td align="right">Phone Number:</td><td align="left">'; $PhoneNumber .'</td></tr>';
$messagetext .= '        <tr><td align="right">Practice Name:</td><td align="left">'; $PracticeName .'</td></tr>';
$messagetext .= '        <tr><td align="right">Message:</td><td align="left">'; $Message .'</textarea></td></tr>';
$messagetext .= '  </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, $messagetext, $headers);
//echo $message;
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'
?>

最佳答案

您在表单中使用了 POST,但没有引用 post 变量。代替 $_GET[$ContactName],使用 $_POST[$ContactName]。对所有 POSTed 变量执行此操作。

关于PHP 表单电子邮件请求不通过表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18791084/

相关文章:

php - 在较大的表单中上传文件(一个页面上的两个表单),如何同时提交两组数据(文件和表单)? (PHP)

javascript - 让 chrome、IE 8 和 Firefox 提交相同表单的奇怪方法

php - 如何在 HTML 中运行 PHP?

html - IE7 和 IE6 在使用无序列表(额外间距等)进行导航时遇到问题

php - 从mysql的两个表中检索数据

php - 单击打印按钮时,HTML 圆形符号丢失

html - 如何拥有基本的html结构?

php - 使用 Laravel 在 Json 列中搜索

php - Yii 通过 many_many 关系查找模型

php - 上传后无法删除文件。 (移动上传文件)