【问题标题】:PHP mailer gmail spam [duplicate]PHP邮件程序gmail垃圾邮件[重复]
【发布时间】:2019-07-19 18:06:44
【问题描述】:

我正在使用 PHPMAILER,而且我还很陌生。

我使用了以下代码,但由于某种原因,电子邮件被发送到垃圾邮件。请看一下代码并告诉我我需要修复什么。 (我是使用电子邮件的新手

<?php
require 'php-mailer-master/PHPMailerAutoload.php';

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isMail();                                     // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'kfhcareer@gmail.com.com';                 // SMTP username
$mail->Password = 'password12345';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('kfhcareer@gmail.com', 'KFH Bahrain');
$mail->addAddress('kfhcareer@gmail.com', 'Joe User');     // Add a recipient
 $mail->AddReplyTo( 'mailer@blah.com', 'Contact BLah' );


$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'KFH house bahrain';
$mail->Body    = 'This is tthe message <b>in bold!</b>';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

【问题讨论】:

  • 尝试删除 AddReplyTo,并保持正文没有 HTML。看看您的邮件是否仍然进入垃圾邮件。然后,如果可行,请将 HTML 添加到正文。如果可行,请添加一个不同的回复地址。
  • @dearsina 不幸的是,这并没有解决我的问题
  • 查看您在 gmail 上收到的邮件的标题,它会显示有关为什么邮件被归类为垃圾邮件的信息。您还运行旧版本的 PHPMailer,因此请升级。

标签: php email smtp gmail phpmailer


【解决方案1】:
require("PHPMailer/class.phpmailer.php");
$sender = "sender@gmail.com"; //gmail of the sender
$password = "senderpassword"; //the password
$receiver = "receiver@gmail.com"; // the receiver email

$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPDebug  = 2; 
$mail->From = $sender;
$mail->FromName = $sender;
$mail->Host = "smtp.gmail.com"; // specif smtp server
$mail->SMTPSecure= "ssl"; // Used instead of TLS when only POP mail is selected
$mail->Port = 465; // Used instead of 587 when only POP mail is selected 465
$mail->SMTPAuth = true;
$mail->Username = $sender; // SMTP username
$mail->Password = $password; // SMTP password
$mail->AddAddress($receiver, $receiver); //replace myname and mypassword to yours
$mail->AddReplyTo($receiver, $receiver);
$mail->WordWrap = 50; // set word wrap


$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "This is Subject";
$mail->Body = "This is Body";

if(!$mail->Send()){
echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

【讨论】:

  • 此代码不适用于最新版本的 PHPMailer,也无助于解决垃圾邮件问题。
  • 代码转储不能提供好的答案。你应该解释如何为什么这可以解决他们的问题。我推荐阅读,“How do I write a good answer?"
  • 这实际上帮助了我伙计们!它工作了 1000%
猜你喜欢
  • 2017-08-31
  • 1970-01-01
  • 1970-01-01
  • 2015-05-18
  • 2017-11-03
  • 2013-05-29
  • 2012-08-24
  • 1970-01-01
  • 2019-12-26
相关资源
最近更新 更多