我在服务器上传了这个php文件,我希望当用户填写此php文件中的html表单时,用户响应应该发送到我在这个php文件中提到的电子邮件地址....但是它不发送对电子邮件地址的回复...请帮助...谢谢
<?php
if ($_POST["email"]<>'') {
$ToEmail = 'abc@gmail.com';
$EmailSubject = 'Site contact form';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die
("Failure");
?>
Your message was sent
<?php
} else {
?>
<form action="test.php" method="post">
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%" class="bodytext">Your name:</td>
<td width="71%"><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input name="email" type="text" id="email" size="32"></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea name="comment" cols="45" rows="6" id="comment"
class="bodytext">
</textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left" valign="top"><input type="submit" name="Submit"
value="Send">
</td>
</tr>
</table>
</form>
<?php
};
?>
答案 0 :(得分:0)
您将电子邮件重新发送到之前定义的变量$ToEmail
。将该变量的值更改为您从表单中获得的值。
尝试:
if ($_POST["email"]<>'') {
$ToEmail = $_POST['email'];
$EmailSubject = 'Site contact form';
$mailheader = "From: abc@gmail.com\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."";
答案 1 :(得分:0)
尝试使用$ mailheader =&#34;来自:admin @ yourdomain&#34 ;;例如来自asd.com的电子邮件必须有$ mailheader =&#34;来自:noreply@asd.com" ;;来自stackoverflow.com的somilarly电子邮件必须有$ mailheader =&#34;来自:admin@stackoverflow.com" ;;用于正宗的电子邮件发在某些情况下,无效的电子邮件标题会导致无法发送电子邮件。