当我尝试在 cakephp 中发送消息或注册新用户时,我收到:
Could not send email.
错误:发生内部错误。堆栈跟踪
CORE\Cake\Network\Email\MailTransport.php line 47 → MailTransport->_mail(string, string, string, string, null)
CORE\Cake\Network\Email\CakeEmail.php line 1066 → MailTransport->send(CakeEmail)
CORE\Cake\Controller\Component\EmailComponent.php line 347 → CakeEmail->send(null)
APP\Plugin\Messages\Controller\MessagesController.php line 158 → EmailComponent->send()
[internal function] → MessagesController->add(string)
CORE\Cake\Controller\Controller.php line 486 → ReflectionMethod->invokeArgs(MessagesController, array)
CORE\Cake\Routing\Dispatcher.php line 187 → Controller->invokeAction(CakeRequest)
CORE\Cake\Routing\Dispatcher.php line 162 → Dispatcher->_invoke(MessagesController, CakeRequest, CakeResponse)
APP\webroot\index.php line 96 → Dispatcher->dispatch(CakeRequest, CakeResponse)
我是 CakePhp 的新手,我在 app/Config/email.php 中编辑了这个文件
public $smtp = array(
'transport' => 'Smtp',
'from' => array('simone.zambenedetti@uniroma1.it' => 'My Site'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => '**user**', //hidden
'password' => '**my secret**', //hidden
'client' => null,
'log' => false
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
还编辑 lib/Cake/Network/Email/CakeEmail.php
protected $_transportName = 'Smtp';
并编辑 lib/Cake/Network/Email/SmtpTransport.php
public function config($config = array()) {
$default = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'simone.zambenedetti@uniroma1.it',
'password' => 'enomis58',
'client' => null,
'tls' => false
);
$this->_config = $config + $default;
}
请帮助我......一切工作,而不是电子邮件或消息。如果您想重新创建错误,您可以在我的网站 http://bbcd.bio.uniroma1.it/eventi/上注册
谢谢大家回答我。
这里的代码:
foreach($usersTo as $userTo) {
if($userTo['User']['notification'] && $userTo['User']['id']!=$this->Auth->user('id')) {
$this->set('message_id', $parent_id);
$this->set('message', $this->request->data['Message']['message']);
$this->Email->reset();
$this->Email->from = Configure::read('evento_settings.systemEmail');
$this->Email->to = $userTo['User']['username'].' <'.$userTo['User']['email'].'>';
$this->Email->replyTo = Configure::read('evento_settings.systemEmail');
$this->Email->return = Configure::read('evento_settings.systemEmail');
$this->Email->subject = __('You have a new message in').' ';
$this->Email->subject.= Configure::read('evento_settings.appName');
$this->Email->delivery = 'mail';
$this->Email->template = 'Messages.new_message';
$this->Email->sendAs = 'both';
$this->Email->send();
//debug($this->Session->read('Message.email'));exit;
}