我已经设置了一个PHP邮件脚本,并且不断出现错误“出了问题,请回去再试一次!”已经检查了所有表单字段并且所有名称都匹配等等,所以我想知道我的脚本是否有问题?
<form method="post" action="contact.php" id="contactForm">
<label for="name">Name</label>
<input type="text" id="name" name="name" class="name" />
<label for="email">Email</label>
<input type="text" id="email" name="email" class="email" />
<label for="phone">Phone</label>
<input type="text" id="phone" name="phone" class="phone" />
<label for="iam">I Am</label>
<select name="iam" class="iam" id="iam">
<option>a recruiter looking to recruit staff</option>
<option>a construction worker looking for work</option>
<option>requesting information</option>
</select>
<label for="message">Message</label>
<textarea name="message" id="message" class="message"></textarea>
<label for="captcha">What is 3+4?</label>
<input type="text" id="captcha" name="captcha" class="captcha" />
<input type="submit" name="submit" id="submit" class="submit" />
</form>
<?php
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$iam = $_POST['iam'];
$human = $_POST['captcha'];
$message = $_POST['message'];
$from = 'From: Test';
$to = 'sales@test.com';
$headers = "From: $email";
$subject = 'Tradeline Contact';
$body = "From: $name\n E-Mail: $email\n Phone Number:\n $phone I Am:\n $iam Message:\n $message";
if ($_POST['submit'] && $human == '7') {
if (mail($to, $subject, $body, $headers, "-f " . $from)) {
echo '<p>Your message has been sent!</p>';
header( 'Location: http://urlhere.com/thankyou.html' ) ;
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '7') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
感谢任何帮助。
答案 0 :(得分:1)
您可能想要更改:
mail($to, $subject, $body, $headers, "-f " . $from)
为:
mail($to, $subject, $body, $headers."\r\n")
这样您的邮件标题就会合规。
此外,打开错误报告。我碰巧在error_reporting(7);
行下使用<?php
来打开所有常见错误,除了捕获未定义的变量,这将告诉我邮件功能是否有问题。
您可以做的另一件事是检查邮件服务器日志以查看邮件是否实际发送。
我确定您已经这样做了,但如果还没有,请确保使用有效的电子邮件地址。