我的邮件是垃圾邮件,我使用php邮箱()

时间:2013-05-26 18:56:31

标签: php email spam

我有一个网站,为注册的人发送一封邮件,绝对不是垃圾邮件。问题是我在PHP中使用mail()函数,但很多人都将其作为垃圾邮件接收。

$title = "title";
$body = "message";
$header = "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$header .= "To: ".$_POST["name"]." <".$_POST["email"].">" . "\r\n";
$header .= "From: SteamBuy <contacto@steambuy.com.ar>" . "\r\n";

mail($_POST["email"], $title, $body, $header, "-f contacto@steambuy.com.ar");

所以我想知道我做错了什么,我该如何解决它。我不希望我的邮件显示为垃圾邮件,因为它们可能包含有价值的信息。

2 个答案:

答案 0 :(得分:4)

重要的部分本身不是mail(),而是您托管网站的主机。因为您的电子邮件包含主机的所有相关信息 - IP等。

由于大多数共享主机,我假设您正在使用一台主机,在一台服务器上托管了大量用户,并且大多数/某些用户可能希望使用mail(),因此电子邮件提供商可能会将主机的IP列入黑名单。这意味着您的网站已包含在该黑名单中。

使用共享主机时无法解决此问题。

答案 1 :(得分:1)

正如@MorganWilde所提到的,电子邮件被标记为垃圾邮件的首要原因是主机列为黑名单。通常这是因为您在共享服务器上,而其他用户可能在过去滥用该服务。

如果您想使用谷歌应用程序smtp服务器发送电子邮件,这是一个很好的方式来被标记为垃圾邮件。唯一的办法是确保谷歌应用程序设置正确,电子邮件发送的内容与您尝试发送的电子邮件相同。使用谷歌应用程序smtp服务器最简单的方法是使用php邮件库,因为mail()函数是非常基本的。以下是一些示例代码,可帮助您开始使用Swiftmailer

<?php
require_once "/Swift-Email/lib/swift_required.php"; // Make sure this is the correct path

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com')
  ->setPort(465)
  ->setEncryption('ssl')
  ->setUsername('EMAIL')
  ->setPassword('PASSWORD');

$mailer = Swift_Mailer::newInstance($transport);
$mailer->registerPlugin(new Swift_Plugins_ThrottlerPlugin(50, Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE));//Add a Throttler Plugin if need be.

$message = Swift_Message::newInstance($emailSubject); // Subject here
$message->setFrom(array('contacto@steambuy.com.ar' => 'Contact'));

// You can choose to only send one version, just replace the second parameter in the setBody() function to the type
$message->setBody(HTML_VERSION, 'text/html'); // Body here
$message->addPart(PLAIN_TEXT_VERSION, 'text/plain'); // and here


$message->setTo($_POST["email"]);

if ($mailer->send($message))
  echo 'Sent';

?>
相关问题