1

わかりました、何時間も試してみて、たくさんの質問とドキュメントを見て、運がありませんでした.

PEAR を使用して gmail アカウントから平文のメールを送信できます。問題はありません。

しかし、リンクが必要だと気づいたので、HTML メールにしたいと思います。ここここここ、その他多くの質問とドキュメントを試しました。

これまでのところ、私は持っています:

$em = new EmailObject;
$em->to = 'recipient@someplace.com';
$em->htmlbody = 'Some HTML msg with a <a href="goto.com?link=true">link</a>';
$em->body = 'Backup text';
$em->sendMail();

class EmailObject
{
    public $to = '';
    public $cc = '';
    public $bcc = '';
    public $subject = '';
    public $body = '';
    public $htmlbody = '';

    function sendMail()
    {
        $headers = array('From' => ***withheld*** ,
                  //'Return-Path' => ***withheld*** ,
                           'To' => $this->to,
/*                           'CC' => $this->cc,
                          'BCC' => $this->bcc, */
                      'Subject' => $this->subject);

        /*if ($this->cc <> '') { $headers['CC'] = $this->cc; }
        if ($this->bcc <> '') { $headers['BCC'] = $this->bcc; }          */  

        $server = array('host' => 'ssl://smtp.gmail.com',
                        'port' => '465',
                        'auth' => true,
                    'username' => ***withheld*** ,
                    'password' => ***withheld*** );
        $clrf = "\n";

        //Tried all sorts here:
        //$mime = new Mail_mime( array('eol' => $clrf, 'text_charset' => 'utf-8', 'html_charset' => 'utf-8') );
        $mime = new Mail_mime();

        $mime->setTXTBody = $this->body;
        $mime->setHTMLBody = $this->htmlbody;

        // Tried all sorts here:
        // $body = $mime->get();
        // $body = $mime->getMessageBody();
        // $body = $mime->getMessageBody(array('eol' => $clrf, 'text_charset' => 'utf-8', 'html_charset' => 'utf-8'));
        $body = $mime->get(array('eol' => $clrf, 'text_charset' => 'utf-8', 'html_charset' => 'utf-8'));
        $headers = $mime->headers($headers);
        $smtp =& Mail::factory('smtp', $server);
        $mail = $smtp->send($this->to, $headers, $body);

        print '<pre>';
        var_dump($body);
        var_dump($headers);        
        print '</pre>';

        /* Working snippet for plain text:
        $smtp = @Mail::factory('smtp', $server);
        $mail = @$smtp->send($this->to, $headers, $this->body);*/

        return PEAR::isError($mail);
    }
}

メールは送信されますが、本文は作成されません。正しい宛先と cc がありますが、メールの本文には何もありません。$body返されたものまたは使用するものをvardumpすると、$mime->get()常にNULLが返されます。何が起こっている?私は何を間違っていますか?

4

1 に答える 1

0

PHPMailer 5.2.0の使用に成功しました。チェックする価値があるかもしれません。他のいくつかはコメントとして投稿されました。髪を引きすぎる前に、別のメールアカウントまたはパッケージを試してみます.

于 2012-10-01T02:23:41.153 に答える