【问题标题】:Error: Transport config "Smtp" is missing in cakephp 3.x错误:cakephp 3.x 中缺少传输配置“Smtp”
【发布时间】:2015-12-03 05:27:22
【问题描述】:

cakephp 3.x 中缺少传输配置“Smtp”

我尝试了一些配置如下:

'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();

非常感谢...

【问题讨论】:

  • 也许你必须使用CakeEmail类而不是Email
  • 在更新的 cakephp 3.x 版本中,没有像 CakeEmail 这样的类。它被电子邮件取代。我用过 CakeEmail,它会给我这个错误。错误:找不到类“App\Controller\CakeEmail”

标签: php email cakephp-3.0


【解决方案1】:

您在Email 中将transport 配置为Smtp,但您尚未在EmailTransport 配置中定义它。

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

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

【讨论】:

  • 已解决。我需要设置“传输”=>“默认”的第一个配置。非常感谢您的知识和方法。
  • 我们需要在 EmailTransport 配置的 Classname 中定义 Smtp。我只这样做了,它工作正常。非常感谢...
【解决方案2】:

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 2016-09-02
    相关资源
    最近更新 更多