0

私はコードイグナイターを使用しています。t@t.com のような間違った実在しないアドレスに電子メールを送信するテストを行います。

私のコードは、そのようなコントローラーの単なるメソッドです:

function test() {
    $this->email->from('mymail@gmail.com');
    $this->email->to(htmlentities("t@t.com"));
    $this->email->subject('test');
    $this->email->message("Just a test !");     

    $r = $this->email->send();      
    if (!$r)
        echo "not sent, wrong email";
    else
        echo "sent";
}

基本的に、send() 関数は true または false を返します。しかし、うまくいきません!私が得たエラーメッセージは次のとおりです。

    A PHP Error was encountered

    Severity: Warning

    Message: mail() [function.mail]: SMTP server response: 550 5.1.2 <t@t.com>: Recipient address rejected: Domain not found

    Filename: libraries/Email.php

    Line Number: 1540

not sent, wrong email

私はメッセージを持っているので、send() 関数は false を返しますが、私は望んでいないエラーメッセージも持っています!

ブロックポイントです。send() 関数が true または false の応答を返さない理由を知っている人はいますか?

よろしくお願いします!

4

2 に答える 2

0

エラーを取り除くための迅速で汚いハックは、メール関数の前に「@」を付けることです。

$r = @$this->email->send();   
于 2012-05-31T07:15:43.027 に答える
0

私はそれを試してみましたが、正常に動作します。

使用している CI のバージョンは何ですか? それが最後であることを確認してください。

念のため、CI フォルダのsystem/librariesの下にあるEmail.phpライブラリを確認してください。

protected function _send_with_mail()
{
    if ($this->_safe_mode == TRUE)
    {
        if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str))
        {
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
    else
    {
        // most documentation of sendmail using the "-f" flag lacks a space after it, however
        // we've encountered servers that seem to require it to be in place.

        if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])))
        {
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
}

内部の関数_send_with_mail()が上記のものとまったく同じであることを確認してください

于 2012-05-30T21:15:28.480 に答える