我不是这方面的专家,但我有以下代码填写查询表格&发送电子邮件但不起作用。只需要两个字段(名称和电子邮件地址),但每次收到错误消息发送表单时出现问题。请检查以确保您已填写所有字段。
我猜它必须是第一部分的东西,但我不能让它起作用, - 任何想法?
<?php
$SENT = false;
if ($_POST && $_POST["name"] && eregi("^[a-zA-Z0-9 ]+$", $_POST["name"]) && $_POST["email"]
&& eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST
["email"])) {
$recipient = "me@mydomain.com";
$recipient = "enquiries@mydomain.com";
$subject = "Enquiry from the Website";
$email_header = "From: " .$_POST["email"]. " (" .$_POST["name"]. ")\r\n";
"Reply-To: " .$_POST["email"]. "";
// build the email
$s = "The following contact form has been submitted:\n\n";
$s .= "=== Customer Details =====\n";
$s .= "Name: " .$_POST["name"]. "\n";
$s .= "Company: " .$_POST["company"]. "\n";
$s .= "Telephone: " .$_POST["telephone"]. "\n";
$s .= "Email Address: " .$_POST["email"]. "\n\n";
$s .= "=== Enquiry Information =====\n";
$s .= trim($_POST["comments"])."\n\n";
$s.= "Generated: " .date("Y-m-d H:i:s");
$email = wordwrap($s, 72). "\n\n\n"; // wrap text to 72 characters
if (@mail($recipient, $subject, $email, $email_header)) {
$SENT = true;
} else {
$SENT = false;
}
}
?>
\\Rest of HTML code here...
<? if (!$SENT) { ?>
<? if (!$SENT && $_POST) { ?>
<p class="red">There was a problem with sending the form.<br />Please check to ensure you have
filled in all the fields.</p>
<? } ?>
<p><b>Enquiry Form</b><br />
<span class="red">**</span> Indicates required fields</p>
<form name="contact" action="contact.php" method="post">
<fieldset class="conform">
<legend>Your Details</legend><br />
<label for="name">Name</label>
<input id="name" type="text" size="40" value="<?php echo (isset($_POST["name"])) ? $_POST
["name"] : '' ; ?>" name="name" /> <span class="red">**</span><br />
<label for="company">Company</label>
<input id="company" type="text" size="40" value="<?php echo (isset($_POST["company"])) ? $_POST
["company"] : '' ; ?>" name="company" /><br />
<label for="telephone">Telephone</label>
<input id="telephone" type="text" size="40" value="<?php echo (isset($_POST["telephone"])) ?
$_POST["telephone"] : ''; ?>" name="telephone" /><br />
<label for="email">Email Address</label>
<input id="email" type="text" size="40" value="<?php echo (isset($_POST["email"])) ? $_POST
["email"] : ''; ?>" name="email" /> <span class="red">**</span><br />
</fieldset>
<fieldset class="conform2">
<legend>Further Information</legend><br />
<textarea id="comments" name="comments" size="40" rows="8" cols="50"><?php echo(isset($_POST
["comments"])) ? $_POST["comments"] : '' ; ?></textarea>
</fieldset>
<br />
<a href="javascript:document.contact.submit();"><img title="" height="43" alt=""
src="images/submit.gif" width="102" border="0" /></a>
</form>
</div>
<?
} else {
?>
<p>Thank you for your enquiry. We will reply as soon as possible.</p>
<?
}
?>
答案 0 :(得分:0)
您的$ email_header声明在“\ r \ n”之后结束。在以“回复:”开头的下一行,它没有被附加到$ email_header。