1

我正在尝试从我的网站向我的 hotmail 帐户发送一个简单的邮件脚本,但它一直以垃圾邮件(cgi 邮件程序)的形式出现。我知道它与标题部分有关,但似乎无法掌握如何让这一切正常工作..这就是我得到的......

<?php 
$name =  $_POST['contact_name'] ;
$email = $_POST['contact_email'] ;
$from= "$name <$email>;"
$company = $_POST['contact_company'] ;
$number = $_POST['contact_phone'] ;

// $message = $_POST['contact_message'], "Name:" . $name,"Telephone Number:" .        $number;
$message = $_POST['contact_message'];
$message .= "Name:" . $name;
$message .= "Telephone Number:" . $number;
$to = "bcplumbing-heating@hotmail.co.uk";
$subject = "ContactForm";
$headers = "From:" . $from;

//modify the mail function
mail($to,$subject,$message,$headers);
?>

任何帮助或建议都会很棒...谢谢

4

4 回答 4

2

您可能想要使用PHPMailer类,它允许您隐藏所有抽象,甚至调试邮件发送

于 2013-06-07T13:08:59.803 回答
1

Hotmail 会进行一些复杂的垃圾邮件检查。这涉及 RBL 列表和反向查找。

  • 因此,例如,当您从test@test.de发送电子邮件时。然后 hotmail 检查来自发送邮件服务器的 IP 是否回到域test.de(反向查找)。

  • 下一点是电子邮件服务器具有正确的配置。

对于应用程序站点来说,也许更好的方法是使用自动生成的邮件系统。

我更喜欢这里Switftmailer

于 2013-06-07T13:03:27.483 回答
0

您的邮件直接进入垃圾邮件箱的原因可能是因为您的邮件headers非常少。

尝试像这样扩展它们:

$headers = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= "FROM: DezeActie.nl <noreply@website.com>" . PHP_EOL;    
$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
$headers .= "Return-Path: noreply@website.com" . PHP_EOL;

要记住的另一件事是header包含FROM:部分必须高于Content-type. 显然,这可以防止它进入垃圾邮件箱(至少,我在 SO 上阅读并亲自尝试过 - 有效)。

您可以headers通过添加进一步扩展

$headers .= "Reply-To: Recipient Name <email@website.com>" . PHP_EOL;

根据我的阅读,这几乎可以防止您的邮件进入垃圾邮件箱,因为您提供了很多有关您的邮件(格式)的信息。

编辑:我看到人们发布关于 PHPMailer 和 SwiftMailer 的帖子。我个人没有使用过它们,但我很确定它们在格式化邮件功能和安全性方面会给您带来很多好处。

于 2013-06-07T13:17:00.657 回答
0

您可以使用 SMTP 从电子邮件服务器(如 gmail)发送邮件,以免将其放入垃圾邮件文件夹。您可以使用此脚本:

电子邮件页面:

<?php
require "email.php";

$mail = new EMail;
$mail->Username = 'somthing@mydomain.co.uk';
$mail->Password = 'thepassword';

$mail->SetFrom("some@address.com","Some name");  // Name is optional
$mail->AddTo("someother@address.com","Someother name"); // Name is optional
$mail->AddTo("someother2@address.com");
$mail->Subject = "Some subject or other";
$mail->Message = "Some html message";

//Optional stuff
$mail->AddCc("someother3@address.com","name 3");  // Set a CC if needed, name optional
$mail->ContentType = "text/html";          // Defaults to "text/plain; charset=iso-8859-1"
$mail->Headers['X-SomeHeader'] = 'abcde';  // Set some extra headers if required
$mail->ConnectTimeout = 30;  // Socket connect timeout (sec)
$mail->ResponseTimeout = 8;  // CMD response timeout (sec)

$success = $mail->Send();

?>

电子邮件.php:

<?php

//email.php: Sends an email using an auth smtp connection
//v3

class EMail
{
  const newline = "\r\n";

  private
    $Server, $Port, $Localhost,
    $skt;

  public
    $Username, $Password, $ConnectTimeout, $ResponseTimeout,
    $Headers, $ContentType, $From, $To, $Cc, $Subject, $Message,
    $Log;

  function __construct()
  {
    $this->Server = "127.0.0.1";
    $this->Port = 25;
    $this->Localhost = "localhost";
    $this->ConnectTimeout = 30;
    $this->ResponseTimeout = 8;
    $this->From = array();
    $this->To = array();
    $this->Cc = array();
    $this->Log = array();
    $this->Headers['MIME-Version'] = "1.0";
    $this->Headers['Content-type'] = "text/plain; charset=iso-8859-1";
  }

  private function GetResponse()
  {
    stream_set_timeout($this->skt, $this->ResponseTimeout);
    $response = '';
    while (($line = fgets($this->skt, 515)) != false)
    {
 $response .= trim($line) . "\n";
 if (substr($line,3,1)==' ') break;
    }
    return trim($response);
  }

  private function SendCMD($CMD)
  {
    fputs($this->skt, $CMD . self::newline);

    return $this->GetResponse();
  }

  private function FmtAddr(&$addr)
  {
    if ($addr[1] == "") return $addr[0]; else return "\"{$addr[1]}\" <{$addr[0]}>";
  }

  private function FmtAddrList(&$addrs)
  {
    $list = "";
    foreach ($addrs as $addr)
    {
      if ($list) $list .= ", ".self::newline."\t";
      $list .= $this->FmtAddr($addr);
    }
    return $list;
  }

  function AddTo($addr,$name = "")
  {
    $this->To[] = array($addr,$name);
  }

  function AddCc($addr,$name = "")
  {
    $this->Cc[] = array($addr,$name);
  }

  function SetFrom($addr,$name = "")
  {
    $this->From = array($addr,$name);
  }

  function Send()
  {
    $newLine = self::newline;

    //Connect to the host on the specified port
    $this->skt = fsockopen($this->Server, $this->Port, $errno, $errstr, $this->ConnectTimeout);

    if (empty($this->skt))
      return false;

    $this->Log['connection'] = $this->GetResponse();

    //Say Hello to SMTP
    $this->Log['helo']     = $this->SendCMD("EHLO {$this->Localhost}");

    //Request Auth Login
    $this->Log['auth']     = $this->SendCMD("AUTH LOGIN");
    $this->Log['username'] = $this->SendCMD(base64_encode($this->Username));
    $this->Log['password'] = $this->SendCMD(base64_encode($this->Password));

    //Email From
    $this->Log['mailfrom'] = $this->SendCMD("MAIL FROM:<{$this->From[0]}>");

    //Email To
    $i = 1;
    foreach (array_merge($this->To,$this->Cc) as $addr)
      $this->Log['rcptto'.$i++] = $this->SendCMD("RCPT TO:<{$addr[0]}>");

    //The Email
    $this->Log['data1'] = $this->SendCMD("DATA");

    //Construct Headers
    if (!empty($this->ContentType))
      $this->Headers['Content-type'] = $this->ContentType;
    $this->Headers['From'] = $this->FmtAddr($this->From);
    $this->Headers['To'] = $this->FmtAddrList($this->To);
    if (!empty($this->Cc))
      $this->Headers['Cc'] = $this->FmtAddrList($this->Cc);
    $this->Headers['Subject'] = $this->Subject;
    $this->Headers['Date'] = date('r');

    $headers = '';
    foreach ($this->Headers as $key => $val)
      $headers .= $key . ': ' . $val . self::newline;

    $this->Log['data2'] = $this->SendCMD("{$headers}{$newLine}{$this->Message}{$newLine}.");

    // Say Bye to SMTP
    $this->Log['quit']  = $this->SendCMD("QUIT");

    fclose($this->skt);

    return substr($this->Log['data2'],0,3) == "250";
  }
}
?>
于 2013-06-07T13:12:00.660 回答