【问题标题】:Sending emails from CakePHP application using Gmail使用 Gmail 从 CakePHP 应用程序发送电子邮件
【发布时间】:2012-08-17 00:20:36
【问题描述】:

我正在尝试让我正在开发的网站发送密码提醒电子邮件。我有使用我的 Gmail 帐户只是为了测试的想法。从蛋糕食谱中,我得到了这个代码:

$this->Email->from = 'support@site.com';
$this->Email->smtpOptions = array(
    'port'=>'465',
    'timeout'=>'30',
    'host' => 'ssl://smtp.gmail.com',
    'username'=>'notmyrealemail@gmail.com',
    'password'=>'notmyrealpassword');
$this->Email->delivery = 'smtp';
$this->Email->from = 'support@imgstore.in';
$this->Email->to = $this->request->data['User']['email'];
$this->Email->subject = 'Your account reset request';
$this->Email->send('testing');
$this->Email->send();
debug($this->Email->smtpError);

但是,当执行此代码时,我收到此错误:

Error: Call to a member function messageID() on a non-object    
File: C:\xampp\htdocs\site\lib\Cake\Controller\Component\EmailComponent.php 
Line: 312

Notice: If you want to customize this error message, create app\View\Errors\fatal_error.ctp

我在这里做错了什么?目前我只想测试我的应用程序是否可以正确发送电子邮件。但是,Gmail 是否是向生产中的用户发送电子邮件的一种不错的方式?

谢谢。

【问题讨论】:

  • 为什么不直接使用本地sendmail? :)
  • 最好使用新的 CakeEmail 类,而不是组件。该错误是由于在调用 send() 之前没有设置主题引起的,尽管您的代码显示您确实设置了它。这是导致这种致命的实际代码吗?你也调用了 send() 两次。

标签: php email cakephp gmail


【解决方案1】:

看起来是您没有将组件类包含到您的控制器中。将EmailComponent 包含到您的控制器文件中。

public $components = array('Email');

【讨论】:

  • 我的控制器中确实包含电子邮件组件。
猜你喜欢
  • 2015-05-06
  • 2023-03-18
  • 2015-07-31
  • 2013-10-17
  • 2016-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多