CakePHP 3未知的电子邮件配置" gmail"在cPanel服务器中

时间:2017-03-01 08:14:59

标签: cakephp

电子邮件已在本地成功发送。但问题出现在生产服务器中,显示错误:未知的gmail配置。

我的电子邮件配置如下:

'gmail' => [

      'className' => 'Smtp',

      // The following keys are used in SMTP transports

      'host' => 'ssl://smtp.gmail.com',

      'port' => 465,

      'timeout' => 60,

      'username' => 'noreplayxxxxx@gmail.com',

      'password' => 'xxxxxxxxxxxxxxxxxxxxx',

      'client' => null,

      'tls' => true,

  ]

问题是什么?我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

确保生产服务器上的app.php文件包含必需的配置。默认情况下,git会忽略app.php,因此可能无法像您期望的那样在您的案例中进行部署。

答案 1 :(得分:-1)

您可以在控制器中使用这些

///////////////////// Configuration /////////////////////////

$host     = 'ssl://smtp.gmail.com';
$username = 'abc@gmail.com';
$password = 'xxxxxxx';
$port     = '465';
$email_to = 'xyz@gmail.com';
$senderName = 'abc';
$email_id_reply ='abc@gmail.com';

$new_attachments = '<some image>';
$msgsend ='Hello!!';

Email::configTransport('WebMail'.$recipient, 
                      [
                        'className' => 'Smtp',
                        'host' => $host,
                        'port' => $port,
                        'timeout' => 30,
                        'username' => $username,
                        'password' => $password,
                        'client' => null,
                        'tls' => null
                      ]
                    );

////////// SEND MAIL 

$transport = ['transport' => 'WebMail'.$recipient];

$email = new Email($transport);

$email  ->template('default','default')
      ->emailFormat('both')
      ->from([$username => $senderName])
      ->to($email_to)
      ->replyTo($email_id_reply)
      ->subject('Client Message');

$email->attachments($new_attachments);  

$response = $email->send($msgsend);