我一直在尝试通过Gmail发送电子邮件与xarp上的Pear发送电子邮件,在花了好几个小时设置它并弄清楚我得到的所有错误后,我认为我是如此接近,直到我开始收到此错误: 控制器动作
public function automail() {
App::uses('CakeEmail', 'Network/Email');
$ret_msg = null;
try {
$is_call_email = true;
$subject = "case detail";
$comment = "Ready to Review";
$email_to = "exmaple@gmail.com";
if ($is_call_email == true) {
$email_to = str_replace(' ', '', $email_to);
$email_addresses = preg_split('/[;,]/', $email_to);
$this->log($is_call_email,'bool');
$email = new CakeEmail();
$email->from(array($this->Session->read('Auth.User.email') => $this->Session->read('Auth.User.name')))
->to($email_addresses)
->subject($subject)
->send($comment);
$this->log($subject,'subject');
}
} catch (Exception $ex) {
$ret_msg = $ex->getMessage();
$this->log($ex->getLine(), 'emailError');
}
$this->log('Return msg is = ' . $ret_msg, 'shared');
return;
在email.php中
<?php
class EmailConfig {
public $default = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'example@gmail.com', //example@gmail.com
'password' => 'secret',
'transport' => 'Smtp',
'from' => array('exampe@gmail.com' => 'Nam Email'),
'log' => true
);
}
来自和来自两个都是相同的电子邮件地址,因为我在我的帐户中发送测试... 请帮助我或任何有关如何使用cakephp发送电子邮件的建议......
答案 0 :(得分:2)
您需要指定$email->config
。像:
$email->config('default')
->from(array($this->Session->read('Auth.User.email') => $this->Session->read('Auth.User.name')))
->to($email_addresses)
->subject($subject)
->send($comment);