我正迈出迈向PHP世界的第一步,并开始使用专为其他网站设计的小脚本。这是一个简单的邮件程序脚本,如下所示:
<?php
if (isset($_POST['name'])) { //form is posted
error_reporting(-1);
$from_email=stripslashes(nl2br($_POST['email']));
$emaildata="";
foreach($_POST as $key => $value)
{
if($key == "name")
$emaildata.="<b>Name:</b> ".stripslashes(nl2br($value))."<br>";
elseif($key == "email")
$emaildata .= "<b>Email:</b> ".stripslashes(nl2br($value))."<br>";
elseif($key == "message")
$emaildata .= "<b>Message:</b> ".stripslashes(nl2br($value))."<br>";
}
$to = 'my.email@gmail.com';
$subject = 'Quick Contact';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= 'From: <'.$from_email.'>' . "\r\n";
$headers .= 'Bcc: test' . "\r\n";
mail($to, $subject, $emaildata, $headers);
echo "<script language=\"javascript\">window.location.href = 'thanks.html';</script>";
die();
}
?>
这适用于以下HTML表单:
<form role='form' style='width:100%;float:left' id="ajax-contact" method="post" action="mailer.php">
<div class='form-group'>
<input type='text' class='form-control text-center' id="name" name="name" placeholder="What's your name, friend?" onfocus='this.placeholder=""' onblur='this.placeholder="What's your name, friend?"' required>
</div>
<div class='form-group'>
<input type='email' class='form-control text-center' id="email" name="email" placeholder="What's your email address?" onfocus='this.placeholder=""' onblur='this.placeholder="What's your email address?"' required>
</div>
<div class='form-group'>
<label class='text-center' style='width:100%'>Tell me about your project</label>
<textarea class='form-control' id="message" name="message" rows='10' required></textarea>
</div>
<button type='submit' class="btn btn-josh" style='width:100%'>Send</submit>
</form>
一切似乎都运行得很好,表格会立即转到感谢页面。 问题是电子邮件没有显示在my.email@gmail.com中。任何见解将不胜感激!
答案 0 :(得分:0)
与您的托管服务提供商联系大多数情况下,托管服务提供商的电子邮件IP被列入黑名单,这会导致您的邮件卡在邮件服务器的SMTP队列中,并且不会传递给收件人。