蛋糕PHP 3 cPanel服务器中未知的电子邮件配置"gmail"



电子邮件已成功发送到本地。但是问题发生在生产服务器中,显示出错误:未知的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,
  ]

问题是什么,我该如何解决此问题?

确保生产服务器上的app.php文件包含所需的配置。默认情况下,git忽略了app.php,因此在您期望的情况下可能不会在您的情况下部署它。

您可以在控制器中使用它们

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

最新更新