在CakePHP中显示无效的电子邮件

时间:2014-06-12 06:02:30

标签: email cakephp

您好,请检查我的CakePHP代码。

代码

    //$from="my_email@domain.com";
    $from="CakePHP Email<my_email@domain.com>";
    $to="someone_email@domain.com";
    $sendMessage="This is CakePHP test message";
    $sendMessage =$message;
    $Email = new CakeEmail();
    $Email->template('default')
        ->emailFormat('html')
        ->to($to)
        ->from($from)
        ->bcc('learnphpchinu@gmail.com')
        ->subject('CakePHP test subject')
        ->send($sendMessage);           
    return true;

此电子邮件无法正常使用。我收到错误消息&#34;电子邮件地址无效CakePHP Email<my_email@domain.com>&#34;。

如果我使用my_email@domain.com代替CakePHP Email<my_email@domain.com>,则电子邮件正常工作,但来自电子邮件的邮件在邮箱中显示my_email

我想在我的电子邮件地址中显示CakePHP Email。我怎么能解决这个问题。帮帮我?

2 个答案:

答案 0 :(得分:4)

因为它将数组作为from name的参数,所以将$from更改为

$from = array('my_email@domain.com' => 'CakePHP Email');

Reference

答案 1 :(得分:-2)

试试这个&gt;

  if (filter_var($d['email_to'], FILTER_VALIDATE_EMAIL)) {

                    $this->Email->sendAs = 'html';
                    $this->Email->from = $d['email_from'];
                    $this->Email->to = $d['email_to'];
                    $this->Email->subject = $d['subject'];
                    $this->Email->send($d['message']);
            }