错误:传输配置" Smtp" cakephp 3.x

时间:2015-12-03 05:27:22

标签: php email cakephp-3.0

Transport config" Smtp" cakephp 3.x中缺少

我尝试了一些配置如下:

'EmailTransport' => [
    'default' => [
        'className' => 'Smtp',
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'username' => 'xxxxxxxxx@gmail.com',
        'password' => 'xxxxx',
    ],
],

'Email' => [
    'default' => [
        'from' => array('site@localhost' => 'Data Mining'),
        'transport' => 'Smtp',
        'charset' => 'utf-8',
        'headerCharset' => 'utf-8',           
    ],
],

我使用以下代码发送电子邮件。

$mail = new Email('default');

$mail->emailFormat('html');
$mail->template($template, null)->viewVars(array('body' => $mailBody));
$mail->to($email_to);
$mail->subject($subject);
$mail->replyTo(Configure::read('config.NOREPLY_EMAIL'));

$headers = array(
    'X-MC-MergeVars' => '{"NAME": "Khushang", "REGARDS":"Khushang"}',
    'X-MC-Template' => 'test-by-Khushang'
);

$mail->setHeaders($headers);
$mail->send();

非常感谢你......

2 个答案:

答案 0 :(得分:4)

您在transport中将Smtp个配置设为Email,但您尚未在EmailTransport配置中对其进行定义。

'transport' => 'Smtp',设为'transport' => 'default',

OR

'default'下的'EmailTransport'设置为'Smtp'

答案 1 :(得分:0)

Cakephp 3x在配置文件夹中设置为app.php

'EmailTransport' => [
        'default' => [
           'className' => 'Mail',
           // The following keys are used in SMTP transports
           'host' => 'localhost',
           'port' => 25,
           'timeout' => 600,
           'username' => 'user',
           'password' => 'secret',
           'client' => null,
           'tls' => null,
           'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
        ],
        'mailjet' => [
           'host' => 'smtp.xxxxxxx.com',
           'port' => 465,//your ssl or none ssl port no
           'username' => 'xxxxxxxxxx', //your smtp mail id
           'password' => '***************', //your email password
           'timeout' => 60,
           'secure' => 'ssl',
           'tls' => false,
           'className' => 'Smtp'
        ]
     ],

您的控制器页面

$email = new Email();
  $email->transport('mailjet');
   $email->from($from)
         //->attachments(TICKET_PDF . $file)
         ->to($to)
         ->emailFormat('html')
         ->subject($subject)
         ->viewVars(array('msg' => $message))
         ->send($message);