简体   繁体   English

由php mail()和smtp单独将gmail标记为垃圾邮件的邮件

[英]Mail marked as spam by gmail alone by php mail() as well as smtp

i have trying to send email to reset user password using php mail() but its sends to spam folder in Gmail Account alone in yahoo mail i can get this mail inside inbox. 我已经尝试使用php mail()发送电子邮件以重置用户密码,但仅在yahoo邮件中将其发送到Gmail帐户中的垃圾邮件文件夹,我可以在收件箱中获取此邮件。 i googled and seen that some of the people says to use smtp mail server via phpmailer. 我用谷歌搜索,发现有些人说通过phpmailer使用smtp邮件服务器。

i tried that too but i get same result as php mail() function did.. here my php mail() function code 我也尝试过,但是我得到了与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);

and php mailer smtp code 和PHP邮件的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!";
}

Your code looks good ok, but if your server's IP address has been added to spam blacklists that are used to filter spam, it wont matter how you send mail from your server. 您的代码看起来还可以,但是,如果服务器的IP地址已添加到用于过滤垃圾邮件的垃圾邮件黑名单中,则从服务器发送邮件的方式就无关紧要。

Do a Google search for something like "mail server blacklist" and test your server's IP address to see if it has been blacklisted. 在Google上搜索“邮件服务器黑名单”之类的内容,然后测试服务器的IP地址以查看其是否已被列入黑名单。 If you are renting the server from a hosting company, changes are your IP address has been used by other people before you. 如果您是从托管公司租用服务器,则更改之处是您的IP地址已被其他人使用。

You can try creating a test Gmail account for your company and try sending out and e-mail from your server using that Gmail account with SMTP and see if the e-mail gets delivered. 您可以尝试为您的公司创建一个测试Gmail帐户,并尝试使用具有SMTP的Gmail帐户从服务器发送和发送电子邮件,然后查看电子邮件是否得到传递。 The e-mail would be sent from the Gmail server on your behalf. 该电子邮件将代表您从Gmail服务器发送。

Another option would be to use a Mailing API service like Mailgin . 另一种选择是使用类似邮寄API服务Mailgin

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

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