PHP邮件功能正在Gmail的SPAM文件夹中发送电子邮件,如何摆脱它?

发布于 2024-10-21 14:08:07 字数 648 浏览 3 评论 0原文

我正在使用此代码:

$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

它将电子邮件发送到我的 gmail 的垃圾邮件文件夹。
提出任何解决方案。

我不想使用任何 PEAR MAIL 类型的方式发送电子邮件或不想要求和包含任何文件。
此函数无需包含/需要任何额外的 php 文件即可工作。

i am using this code :

$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";

it sends email to my gmail's SPAM folder .

Suggest any solution .

i dont want to use any PEAR MAIL type way to send email or dont want to require and include any file.

This functions works without including/requiring any additional php file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦年海沫深 2024-10-28 14:08:07

您应该使用 PHP 手册中的正确标头

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

You should use proper header like this from PHP manual

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
神爱温柔 2024-10-28 14:08:07

Gmail 垃圾邮件过滤器有很多部分可以确定邮件是否为垃圾邮件。您可以首先查看您的域的 SPF 记录。尽可能避免在电子邮件中使用销售语言、HTML 和颜色。

Google 还提供了一个古老但有趣的视频,介绍了垃圾邮件过滤的工作原理。

The Gmail spam filter has lots of parts to it which determine the spamminess of mail. You could start by seeing the SPF record for your domain. Avoid using sales language, HTML and colours where possible in your email.

There's also an old but fun video from Google about how their spam filtering works.

爱情眠于流年 2024-10-28 14:08:07

一切都在标题中。我不知道 GMail 内部是如何工作的,但我在我的项目中发现设置 Reply-To 可以 Content-Type 标头似乎可以解决此问题。

有关执行此操作的示例,请参阅 PHP mail() 文档

(注意:我有一个 PHP 调查问卷/响应系统,可以设置这些标头,并且电子邮件可以正确发送到 GMail、Hotmail 和 Yahoo! Mail)。

It's all in the headers. I don't know how GMail works internally, but I've found on my projects that setting Reply-To can Content-Type headers seems to fix this.

See PHP mail() docs for an example of doing this.

(Note: I've got a PHP questionnaire/response system that sets these headers and the e-mails come through correctly to GMail, Hotmail and Yahoo! Mail).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文