【问题标题】:Mail marked as spam by gmail alone by php mail() as well as smtp邮件由 gmail 单独由 php mail() 以及 smtp 标记为垃圾邮件
【发布时间】:2016-04-12 17:27:10
【问题描述】:

我尝试使用 php mail() 发送电子邮件以重置用户密码,但它仅在 yahoo 邮件中发送到 Gmail 帐户中的垃圾邮件文件夹,我可以在收件箱中收到此邮件。我用谷歌搜索,看到有些人说要通过 phpmailer 使用 smtp 邮件服务器。

我也试过了,但我得到了与 php mail() 函数相同的结果.. 这里是我的 php mail() 函数代码

$headers  = 'From: no-reply@mydomain.us' . "\r\n";
$headers .= 'Reply-To: '.$to.'';
$headers .= 'Subject: ' . $subject ." \r\n";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset="iso-8859-1"'. "\r\n";
@mail($to, $subject, $msg, $headers);

和php mailer smtp代码

 date_default_timezone_set('Etc/UTC');

require_once 'PHPMailerAutoload.php';

$mail = new PHPMailer;

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'mydomain.us';

// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "cs@mydomain.us";

//Password to use for SMTP authentication
$mail->Password = "pass";

//Set who the message is to be sent from
$mail->setFrom('cs@umydomain.us.us', 'sender name');

//Set an alternative reply-to address
$mail->addReplyTo('cs@mydomain.us', 'sender name');

//Set who the message is to be sent to
$mail->addAddress($to, 'John Doe');

//Set the subject line
$mail->Subject = $subject;

//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML($msg);

//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';

//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

【问题讨论】:

  • 您的邮件是否最终成为垃圾邮件与您发送它的方式没有太大关系,而与您发送的内容和收件人的处理方式有关。如果收件人将其标记为垃圾邮件,不久之后,gmail 将默认开始这样做。 Gmail 有将几乎所有内容标记为垃圾邮件的历史,而且情况越来越糟。

标签: php smtp phpmailer email-spam


【解决方案1】:

您的代码看起来不错,但是如果您的服务器的 IP 地址已被添加到用于过滤垃圾邮件的垃圾邮件黑名单中,那么您如何从服务器发送邮件都没有关系。

在 Google 上搜索“邮件服务器黑名单”之类的内容,然后测试您的服务器的 IP 地址,看看它是否已被列入黑名单。如果您从托管公司租用服务器,则更改是您的 IP 地址在您之前已被其他人使用。

您可以尝试为您的公司创建一个测试 Gmail 帐户,并尝试使用该 Gmail 帐户和 SMTP 从您的服务器发送电子邮件,然后查看电子邮件是否已送达。电子邮件将代表您从 Gmail 服务器发送。

另一种选择是使用邮件 API 服务,例如 Mailgin

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 2012-08-24
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多