【问题标题】:Sending email from PHP using SMTP and email goes to spam.What will be easiest way to send email to inbox? [duplicate]使用 SMTP 从 PHP 发送电子邮件,电子邮件进入垃圾邮件。将电子邮件发送到收件箱的最简单方法是什么? [复制]
【发布时间】:2017-05-12 16:26:10
【问题描述】:

我正在尝试使用 SMTP 从 PHP 发送电子邮件,但每次我都收到垃圾邮件中的电子邮件。我在谷歌上搜索并得到了一些解决方案,但我仍然收到垃圾邮件。你会在这方面帮助我吗?

//$mail->isSMTP();                                      // Set mailer to use SMTP

$mail->Host = 'smtp.gmail.com';                       // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'abc@gmail.com';                   // SMTP username
$mail->Password = '***';               // SMTP password
$mail->SMTPSecure = 'tls';         // Enable encryption,'ssl' also accepted
$mail->Port = 587;                                    //Set the SMTP port number - 587 for authenticated TLS
$mail->setFrom('abc@gmail.com', 'admin');     //Set who the message is to be sent from
$mail->addReplyTo('abc@gmail.co', 'First Last');  //Set an alternative reply-to address
$mail->addAddress($to, 'user');  // Add a recipient
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'Hello';
$mail->Body    = "<html>
<head>
<title>HTML email</title>
</head>
<body>
<a href='/changepassword.php?user_id=" .$User_id1."'>Create your password here</a>
</body>
</html>";
if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

【问题讨论】:

标签: php email email-spam


【解决方案1】:
// Use phpmailer library from github install and use
require_once('PHPMailer/PHPMailerAutoload.php');
if(isset($_REQUEST['submit']))
{
    $mail = new PHPMailer(); // defaults to using php "mail()"

    $body = "Name : ".$_REQUEST['name']."<br> Email Id ".$_REQUEST['email']."<br> message ".$_REQUEST['message'];

    $mail->IsSMTP();                                      // set mailer to use SMTP
    $mail->SMTPAuth = true; // authentication enabled
    $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = "mail.xx.co";
    $mail->Port = 25; 
    $mail->Username = "support@xx.co";  // SMTP username
    $mail->Password = "xxxxxxxxxx"; // SMTP password
    $mail->SetFrom('support@xx.co',$_REQUEST['subject']);
    $mail->AddAddress('support@xx.co', $_REQUEST['name']);
    $mail->IsHTML(true);                                  // set email format to HTML
    $mail->Subject = $_REQUEST['subject'];
    $mail->Body    = $body;

    if(!$mail->Send()) {
      echo '<strong>Email</strong> sent failed.';
    } else {
      echo '
        <strong>Email</strong> s`enter code here`ent successfully.';
    }
}

// get smtp host detail from the cpanel

【讨论】:

    【解决方案2】:

    您的问题不是由您的代码引起的。

    您需要确保电子邮件来自与您发送邮件的域相关联的服务器。

    您发送的每封电子邮件都需要根据Sender Policy Framework 使用SPF record 签名,以免最终进入垃圾邮件箱。

    您通常可以自己将 SPF 记录添加到您的 DNS。

    要检查的另一件事是,您使用的 SMTP 服务器未以任何方式列入黑名单。

    【讨论】:

    • 感谢 Darryn.ten 先生的回复,我从 Gmail 向 Gmail 发送了电子邮件,但仍然收到垃圾邮件
    • 还有其他发送电子邮件的方法吗?
    • 你不明白我在说什么,如果它太难研究和遵循,那么使用像 mailchimp/mailgun 这样的商业服务来解决你的问题。
    猜你喜欢
    • 2013-10-17
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    • 2012-05-27
    • 2016-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多