使用gmail smtp通过phpmailer发送邮件,发送垃圾邮件

时间:2017-09-01 09:42:13

标签: php email

使用PHPMailer 5.2。

当通过phpmailer发送的邮件最终发送到垃圾邮件文件夹时。

在测试ip时,它工作正常,用于仅接收邮件到收件箱。 一旦它在实时域上托管,邮件就会转到垃圾邮件文件夹。

使用gmail smtp凭据。

以下是我用来访问phpmailer的代码。

          <?php
       require 'phpmailer/class.phpmailer.php';

$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$message = $_REQUEST['message'] ;
$subject = 'Enquiry' ;
$email_status='';
$message_body='';

$message_body='
Hello,<br>
<p>You have a enquiry request below</p>
<table>
<tr>
<td>Name</td><td>'.$name.'</td>
</tr>
<tr>
<td>Email</td><td>'.$email.'</td>
</tr>
<tr>
<td>Message</td><td>'.$message.'</td>
</tr>
</table>
<br>
Thank you,<br>
Support Team
';

try {
  $mail = new PHPMailer(true); //New instance, with exceptions enabled

  //$body             = file_get_contents('contents.html');
  $body             = $message_body;

  $mail->IsSMTP();                           // tell the class to use SMTP
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->Port       = 587;                    // set the SMTP server port
  $mail->Host       = "smtp.gmail.com"; // SMTP server
  $mail->Username   = "mymail@gmail.com";     // SMTP server username
  $mail->Password   = "12345";            // SMTP server password

  $mail->IsSendmail();  // tell the class to use Sendmail

 // $mail->AddReplyTo("mymail@gmail.com","mymail");

  $mail->From       = "mymail@gmail.com";
  $mail->FromName   = "mymail";

  $to = "yourmail@gmail.com";

  $mail->AddAddress($to);

  $mail->Subject  = $subject;

  $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  $mail->WordWrap   = 80; // set word wrap

  $mail->MsgHTML($body);

  $mail->IsHTML(true); // send as HTML

  $mail->Send();
  $email_status='success';
 // echo 'Message has been sent.';
 // echo "<script>alert('Thank you . We will get back to you soon.');document.location='contact.php'</script>";

} catch (phpmailerException $e) {
  //echo $e->errorMessage();
  $email_status='fail';
}
 header( 'Location: contact.php?email_status='.$email_status);
?>

对此提出任何建议。我应该对phpmailer类进行任何修改。

0 个答案:

没有答案
相关问题