所有邮件服务器都可以接受PHP邮件配置

时间:2014-03-03 07:21:08

标签: php email

我在注册后立即使用电子邮件检查。我使用ubuntu 13.10服务器的本地sendmail(它有Postfix)。问题是,我没办法用所有邮件服务器测试它。我知道有些服务器没有从我的服务器接收电子邮件。 实际上像gmail这样的服务器,hotmail从服务器获取电子邮件。但是像mail.ru这样的服务器(我经过测试,既没有垃圾也没有收件箱收到邮件)都没有收到我服务器的电子邮件。这是我的邮件类,它与PHPMailer一起使用。

<?php

class Mail
{
    private $mail;

    public function __construct()
    {
        $this->mail = new PHPMailer(true);

        $this->mail->IsSendmail();
        $this->mail->WordWrap = 50;
        $this->mail->CharSet = "UTF-8";
        $this->mail->IsHTML(true);

    }

    public function SendIt($to, $from_mail, $from_name, $subject, $message)
    {
        $this->mail->AddReplyTo($from_mail, $from_name);
        $this->mail->SetFrom($from_mail, $from_name);
        $this->mail->Subject = $subject;
        $this->mail->Body = $message;
        $this->mail->AddAddress($to);
        if ($this->mail->Send())
            return true;
        else {
            Yii::log('Mail error: ' . $this->mail->ErrorInfo, "error", "mail");
            return false;
        }

    }

}

我做错了什么?有什么建议?也许我必须使用一些标题?

1 个答案:

答案 0 :(得分:0)

我建议你简单地使用PHPMAILER类来为你自己休息一下。

https://code.google.com/a/apache-extras.org/p/phpmailer/

这对你有很好的帮助,所以你不需要开始编写很多代码,这会耗费你的时间用于其他工作。

检查示例文件夹中为SMTP示例提供的文件,并使用SMTP高级或基本版。使用SMTP高级,您将能够抛出并捕获您的错误。这可以帮助您在出现所有错误之前了解错误。请参阅SMTP基本代码的示例代码。

require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if      not already loaded

$mail             = new PHPMailer();

$body             = file_get_contents('contents.html');
$body             = preg_replace('/[\]/','',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                       // 1 = errors and messages
                                       // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "yourname@yourdomain"; // SMTP account username
$mail->Password   = "yourpassword";        // SMTP account password

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";   // optional, comment out and test

$mail->MsgHTML($body);

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
   echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

完成测试并希望现在停止输出SMTP缓冲区消息后,找到显示

的行
$mail->SMTPDebug = 2;
and replace it with

$mail->SMTPDebug = false;
$mail->do_debug = 0;
相关问题