skip to Main Content

Email are sent successfully in local. But the problem occurs in production server that shows an error: unknown gmail configuration.

My email configuration looks like:

'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,

  ]

What is the problem and how can I fix this problem?

2

Answers


  1. You can use these in your controller

    ///////////////////// 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);
    
    Login or Signup to reply.
  2. Make sure app.php file on your production server contains required configuration. app.php is ignored by git by default, so it might not get deployed in your case as you are expecting.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search