我的网站上有2个地方实施了一些代码。
由于某种原因,表单每次都无法发送。下面是代码,我已经通过语法检查程序运行它,就这一点而言没问题。
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$from = 'From: Roofing Solutions Contact Form';
$to = 'info@allroofingsolutions.com';
$subject = 'Question Sent From Website Form';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Number: $number\n Message:\n $message";
if ($_POST['submit'] && $human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
所以我对它感到困惑。为了安全起见,这里是html表单:
<form method="post" action="contactform.php">
<label>Name</label>
<input name="name" placeholder="Type Here">
<label>Email</label>
<input name="email" type="email" placeholder="Type Here">
<label>Contact Number</label>
<input name="number" placeholder="Type Here">
<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
<input id="submit" name="submit" type="submit" value="Submit">
</form>
感谢您的帮助。
答案 0 :(得分:0)
add header part..
/ 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";
答案 1 :(得分:0)
我不知道你对身体和信息做了什么,这对我来说很奇怪。表格应该在标题中, 最常规的解决方案: 你的PHP部分:
$to = 'info@allroofingsolutions.com';
$subject = 'Question Sent From Website Form';
$message = "E-Mail: ".$_POST['email']."\n<br />Number: ".$_POST['number']."\n<hr />Message:\n ".$_POST['message'];
$headers = "From: Roofing Solutions Contact Form <".$to.">\r\n" ;
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n" ;
if ($_POST['submit'] && _POST['human'] == '4') {
if (mail ($to, $subject, $message, $headers)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && _POST['human'] != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}