简体   繁体   English

使用CakePHP发送电子邮件与CakeEmail和SwiftMailer一起无法使用

[英]Sending emails with CakePHP not works using CakeEmail and also SwiftMailer

I'm trying to send emails from CakePHP but without success. 我正在尝试从CakePHP发送电子邮件,但没有成功。 I'm trying with CakeEmail and this code: 我正在尝试使用CakeEmail和以下代码:

$email = new CakeEmail();
$email->from(array('reynierpm@gmail.com' => __('Recruitment Job App')))
      ->to('reynierpm@gmail.com')
          ->subject(__('Recruitment Status Update'))
          ->send(__('Dear, ReynierPM this is a testing email'));

And doesn't work because no emails is send. 而且不起作用,因为没有电子邮件发送。 The file /app/Config/email.php have this configuration: 文件/app/Config/email.php具有以下配置:

class EmailConfig {
   public $default = array(
    'transport' => 'Debug',
    'host' => 'smtp.gmail.com',
    'port' => 25,
    'timeout' => 30,
    'username' => 'mlrepemi@gmail.com',
    'password' => 'secret_password',
    'charset' => 'utf-8',
    'headerCharset' => 'utf-8',
);  
}

I've try also this http://bakery.cakephp.org/articles/sky_l3ppard/2009/11/07/updated-swiftmailer-4-xx-component-with-attachments-and-plugins but in this case I get this error: 我也尝试了这个http://bakery.cakephp.org/articles/sky_l3ppard/2009/11/07/updated-swiftmailer-4-xx-component-with-attachments-and-plugins,但是在这种情况下,我得到了错误:

Fatal error: Class 'testemailView' not found in /var/www/html/jobapp/app/Controller/Component/swift_mailer.php on line 245 致命错误:在第245行的/var/www/html/jobapp/app/Controller/Component/swift_mailer.php中找不到类'testemailView'

I'm using CakePHP 2.0.6 and SwiftMailer 4.1.5, any help? 我正在使用CakePHP 2.0.6和SwiftMailer 4.1.5,有什么帮助吗? Cheers and thanks in advance 预先加油和感谢

You are leaving out some important parts to enable email. 您遗漏了一些重要的部分来启用电子邮件。 You should have something like this: 您应该具有以下内容:

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('default');

Then in your email.php config, your default configuration for gmail should looke like this: 然后在您的email.php配置中,您的gmail默认配置应如下所示:

public $default = array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => 465,
    'timeout' => 30,
    'username' => 'my@gmail.com',
    'password' => 'secret',
    'transport' => 'Smtp'
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM