2017-03-01 105 views
0

電子郵件在本地成功發送。但是生產服務器出現問題,顯示錯誤:未知的gmail配置。CakePHP 3 cPanel服務器中的未知電子郵件配置「gmail」

我的電子郵件地址的配置是這樣的:

'gmail' => [ 

     'className' => 'Smtp', 

     // The following keys are used in SMTP transports 

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

     'port' => 465, 

     'timeout' => 60, 

     'username' => '[email protected]', 

     'password' => 'xxxxxxxxxxxxxxxxxxxxx', 

     'client' => null, 

     'tls' => true, 

    ] 

什麼問題,如何解決這個問題?

+1

可能是你沒有在服務器上傳適當的app.php文件 – tarikul05

回答

-1

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

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

$host  = 'ssl://smtp.gmail.com'; 
$username = '[email protected]'; 
$password = 'xxxxxxx'; 
$port  = '465'; 
$email_to = '[email protected]'; 
$senderName = 'abc'; 
$email_id_reply ='[email protected]'; 

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

使您的生產服務器上肯定app.php文件包含所需的配置。 app.php在默認情況下被git忽略,所以它可能不會像你所期望的那樣被部署在你的案例中。

相關問題