简体   繁体   English

PHPMailer、DKIM 和 SPF 设置 - 电子邮件仍以垃圾邮件形式送达 (PHP)

[英]PHPMailer, DKIM, and SPF set - Emails still arriving in Junk (PHP)

I am trying to send an activation email from my website to the user.我正在尝试从我的网站向用户发送激活电子邮件。 No matter what I do, the email is going straight to the junk folder.无论我做什么,电子邮件都会直接进入垃圾文件夹。

I have logged into my cPanel, gone to E-Mail Authentication and enabled Domain Keys and SPF, but to no avail.我已登录我的 cPanel,进入电子邮件身份验证并启用域密钥和 SPF,但无济于事。

It's also worth mentioning that I'm using PHPMailer class with the default mail() type.还值得一提的是,我将 PHPMailer 类与默认的 mail() 类型一起使用。 I tried using sendmail, but it was unable to execute (shared host), and I tried SMTP, but I don't have the details for that (as far as I know).我尝试使用 sendmail,但它无法执行(共享主机),我尝试了 SMTP,但我没有详细信息(据我所知)。

Is there anything else I need to do?还有什么我需要做的吗?

Here is the code that is sending the email for your reference.这是发送电子邮件以供您参考的代码。

if (isset($_SESSION['registered'])) {
    require_once '/home/wwwmcser/public_html/inc/vendor/class.phpmailer.php';

    //mail
    $mail = new PHPMailer;
    $mail->SetFrom('team@mcserverranks.com','MCSR Team');
    $mail->AddReplyTo('noreply@mcserverranks.com','No Reply');
    $mail->AddAddress($_SESSION['userEmail'],$_SESSION['userName']);
    $mail->Subject = 'Verify your account || MCServerRanks';
    $mail->Body = "removed";
    $mail->AltBody = "removed";
    if (!$mail->Send()) {
        $_SESSION['mailErr'] = 'There was an error sending your mail. This has been reported. Please contact support for assistance.';
        error_log('Mailer Error: ' . $mail->ErrorInfo);
    }
    unset($_SESSION['userEmail']);unset($_SESSION['userName']);unset($_SESSION['activateHash']);
    //show page
    //rest of page is shown below, but I've removed that

Make sure the SPF records are added to the DNS TXT record.确保将 SPF 记录添加到 DNS TXT 记录。 SPF record is relative to the domain you use for expedition So if you want to send an E-mail as user@foo.bar from IP address 192.168.3.4 you need to create (if you are not the admin of foo.bar) a DNS TXT record/s for foo.bar as such SPF 记录是相对于您用于探险的域所以如果您想从 IP 地址192.168.3.4以 user@foo.bar 的身份发送电子邮件,您需要创建(如果您不是 foo.bar 的管理员) foo.bar 的 DNS TXT 记录/s

v=spf1 +ip4:192.168.3.4 -all

This tells the remote server that the foo.bar domain sends legitimate email from 192.168.3.4 and that all other sources are only pretending to be foo.bar.这告诉远程服务器 foo.bar 域从 192.168.3.4 发送合法电子邮件,而所有其他来源只是假装是 foo.bar。

Note that the IP can be either ip4 or ip6.请注意,IP 可以是 ip4 或 ip6。

Also you can add Subnets, FQDN names, MX records, or include SPF records from other domains, use a single SPF record per domain with as many items as needed您还可以添加子网、FQDN 名称、MX 记录或包括来自其他域的 SPF 记录,每个域使用单个 SPF 记录,并根据需要使用多个项目

See SPF Documentation请参阅SPF 文档

This is happening due to the irregularities with in the Host address and From Address which You are sending the mail.这是由于您发送邮件的主机地址和发件人地址不规范造成的。 If both these address doesn't belongs to same server then the mailing app will detect that mail as spam or junk.如果这两个地址不属于同一服务器,则邮件应用程序会将该邮件检测为垃圾邮件或垃圾邮件。

$mail->Host='mail.developerbaijan.com';
$mail->Username='developerbaijan@gmail.com';

This will obviously resulting in junk mail due to the irregularity in host and user.由于主机和用户的不规则性,这显然会导致垃圾邮件。 If the from address is so may also end up the mail in the same.如果发件人地址是这样,则邮件也可能以相同的方式结束。

You Should try like this你应该像这样尝试

$mail->Host='mail.google.com';
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->SMTPSecure='tls';
$mail->Username='username@google.com';
$mail->Password='*********';
$mail->setFrom('username@google.com','name');

将您的地址设置为他们在自动电子邮件中的地址,以便他们从看似自己的电子邮件中收到一封电子邮件,标题为“需要身份验证.. 成功”等 - 这将防止垃圾问题,但可能会使某些人感到困惑客户,除非现场指定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM