2016-12-28 155 views
0

我想使用SMTP发送来自PHP的电子邮件,但每次我收到我的垃圾邮件中的电子邮件。我在谷歌搜索,并得到了一些解决方案,但我仍然收到垃圾邮件的电子邮件。你能帮我吗?使用SMTP和电子邮件从PHP发送电子邮件转到spam.What是最简单的方式发送电子邮件到收件箱?

//$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 = '[email protected]';     // 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('[email protected]', 'admin');  //Set who the message is to be sent from 
$mail->addReplyTo('[email protected]', '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; 
} 
+1

结帐:http://stackoverflow.com/questions/746809/prevent-sent-emails-treated-as-junk-mails-using-php-mail-function – Ajay

+0

试图找到全球的IP地址黑名单。 – nagiyevel

+0

谢谢答复Mr.Ajay。我也检查过,但仍然收到垃圾邮件。 –

回答

0

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

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

您发送的每封电子邮件都需要使用SPF record进行签名,根据Sender Policy Framework才能最终保留在垃圾邮件箱中。

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

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

+0

感谢您的回复Mr.darryn.ten,我从Gmail发送邮件到Gmail,但仍然收到垃圾邮件 –

+0

是否有任何其他方式发送电子邮件? –

+0

你不理解我在说什么,如果研究和追踪太难了,那就用mailchimp/mailgun这样的商业服务来解决你的问题。 –

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 = "[email protected]"; // SMTP username 
    $mail->Password = "xxxxxxxxxx"; // SMTP password 
    $mail->SetFrom('[email protected]',$_REQUEST['subject']); 
    $mail->AddAddress('[email protected]', $_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