How to configure mail.php and service.php in laravel 9 project when i use Sendinblue smtp service - smtp

In development it works perfectly, the emails reach the recipient, but when I display the project in cpanel I get a 500 error when my client presses the send button.
Currently my configuration is like this:
.ENV:
MAIL_MAILER=smtp
MAIL_HOST=smtp-relay.sendinblue.com
MAIL_PORT=587
MAIL_USERNAME=myEmailUserSendinblue
MAIL_PASSWORD=passwordMySendiblueService
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="EmailClient"
MAIL_FROM_NAME="${APP_NAME}"
SENDINBLUE_API_KEY=xxxxxxxxxxxxxxxxxxxxxxx
mail.php:
'mailers' => [
'sendinblue' => [
'transport' => 'sendinblue',
'host' => env('MAIL_HOST', 'smtp-relay.sendinblue.com'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
],
services.php:
return [
'sendinblue' => [
'api_key' => env('SENDINBLUE_API_KEY'),
],
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
'scheme' => 'https',
],
'postmark' => [
'token' => env('POSTMARK_TOKEN'),
],
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
];
Thank you very much in advance, I remain attentive to your comments.
EDIT 1:
I got an error through the laravel logs, it is as follows:
production.ERROR: Unsupported mail transport [sendinblue]. {"exception":"[object] (InvalidArgumentException(code: 0): Unsupported mail transport [sendinblue]. at /home/-------/public_html/vendor/laravel/framework/src/Illuminate/Mail/MailManager.php:157)
[stacktrace]

Related

SwiftMailer - Yii2 can't send email

I have problem using swiftmailer with yii2.
'components' => [
'mailer' => [
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.mandrillapp.com',
'port' => 587,
'username' => 'noreply#mysociete.com',
'password' => 'MY API KEY HERE',
],
],
],
to send after user registration i use the code below :
$isSuccessfullySaved = $leadModel->save();
if (!$isSuccessfullySaved) {
$response = $this->asJson(['errors' => ['webservice' => 'Error while saving the lead']]);
$response->statusCode = 550;
return $response->send();
}
$lastStep = Json::decode(file_get_contents(__DIR__ . '/../config-offers/offers.json'));
$isSuccessfullySent = Yii::$app->mailer->compose(
'offer-summary',
ArrayHelper::merge($leadModel->getAttributes(), $lastStep['offres'][$bestOffer])
)
->setFrom(['noreply#mysociete.com' => 'My Societe'])
->setTo($leadModel->emailAddress)
->setSubject('mysociete.com- Votre offre')
->send();
if (!$isSuccessfullySent) {
Yii::error("Could not send the email", __METHOD__);
}
What should be wrong. There is no error written in any log.
Have you tried setting the encryption in the transport? I am not sure about Mandrillapp needing it, but you could give it a try:
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.mandrillapp.com',
'port' => 587,
'username' => 'noreply#mysociete.com',
'password' => 'MY API KEY HERE',
'encryption' => 'tls',
],

Cakephp Email Not Working after Upgrade 3.5.2 --> 3.6.7

I've upgraded my CakePHP app from 3.5.2 to 3.6.7. My email functionality no longer works in the new version.
The email transport in config/app.php is:
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'timeout' => 30,
'username' => 'user#domain.com',
'password' => 'secret',
'client' => null,
'context' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
],
'tls' => true,
],
],
And, the email sending code is:
$email = new Email('default');
$email->addTo($user['email'], $user['fullname']);
$email->viewVars([
'messagebody' => 'Hello, I am the message body of the email',
]);
$email->setTemplate('mytemplate','mylayout')
->emailFormat('html')
->setFrom(['sender#domain.com' => __('Sender Name')])
->setSubject(__('Welcome Email'))
->helpers(['Html'])
->send();
This works perfectly in 3.5.2. However, in 3.6.7, I get an error as follows:
Notice (8): Undefined index: debugKitLog [ROOT\vendor\cakephp\debug_kit\src\Mailer\Transport\DebugKitTransport.php, line 37]
The context of the notice is:
$config = [
'host' => 'smtp.gmail.com',
'port' => (int) 587,
'timeout' => (int) 30,
'username' => 'user#domain.com',
'password' => 'secret',
'client' => null,
'context' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
],
'tls' => true
]
$originalTransport = null
Note, the same error occurs when using the Debug Kit's mail preview. Again, in 3.5.2 there are no errors, and emails send correctly. The errors only occur in 3.6.7.
Can anyone advise how to solve this? And what changed in recent versions of CakePHP to cause it?
Thanks in advance for any help or advice.
DBZ
Fixed the issue... was related to loading the debugkit plugin improperly in config/bootstrap.php

Yii2 mail in not sending on portal.azure.com

I have migrate a Yii2 website from Apache server to portal.azure.com windows server. I have checked that mail is not sending on windows server.
Do anyone have any idea, what I have missed in this.
Thanks
I have used send-grid(https://sendgrid.com/) to setup mail system in Yii2 on portal.azure.com. It should be like below:-
'components' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.sendgrid.net',
'username' => 'azure_************#azure.com',
'password' => '***********',
'port' => '25',
//'encryption' => 'tls',
],
],
],

Swiftmailer from Advanced Yii 2.0 does not work with gmail

I'm trying to configure swiftmailer in the advanced yii 2.0 template. I've gone through many posts and I understand that there are some issues with gmail. My configuration environment in development is the following:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => gethostbyname('smtp.gmail.com'),
'username' => 'xxx#gmail.com',
'password' => 'xxssxxxx',
'port' => '465',
'encryption' => 'ssl'
]
I've also set the support mail that's used in the controller to the same gmail address in the main-local config shown above.
I've tried switching to a less secure configuration for apps in the gmail account and it did not work and I'm not particularly fond on changing this. I get the following error when I use ssl encryption
connection could not be established with host ... [ #0]
If I don't specify the encryption I get a time out error.
I have OpenSSL support enabled according to my phpinfo file but I cannot make it work. TLS does not work either because if I change the config (port:'587' & encryption='tls') I get the following error
stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Any ideas on how can I fix this? Is this an unfixed issue? Should I use another mailing extension?
The options can be set like this:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => gethostbyname('smtp.gmail.com'),
'username' => 'xxx#gmail.com',
'password' => 'xxssxxxx',
'port' => '465',
'encryption' => 'ssl',
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]
]
Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack. Be sure you fully understand the security issues before using this as a solution.
Try using the gmail smtp IP
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => '64.233.171.108',
'username' => 'XXXXXXX#gmail.com',
'password' => 'XXXXXXX',
'port' => '587',
'encryption' => 'tls',
],
Some production servers cannot solve FQDN via DNS servers
For gmail: encryption must be setted to tls, port to 587 and host to smtp.gmail.com (check if your gethostbyname('smtp.gmail.com'), get the correct value) see the sample below:
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'yourUsername#gmail.com',
'password' => 'yourPassword',
'port' => '587',
'encryption' => 'tls',
],
Please check :
Internet connection
email Configuration
This is my configuration. An Email succesfuly send.
'components'=>[
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#app/mail',
'useFileTransport' => false,
'transport' => [
'class'=>'Swift_SmtpTransport',
'host'=>'smtp.gmail.com', //sample
'username'=>'my#emaul.com', //sample email
'password'=>'~!##$%%^&&', // sample password
'port'=>'465', // gmail ssl use port 465,
'encryption'=>'ssl',
],
],
],
I had this issue my oversight being i was connecting with tls as my encryption , while the remote server only supported the older ssl encryption.
All i did was to change my encryption parameter value from "tls" to "ssl" and everything worked.
I hope this helps someone.
Adding streamOptions solved my problems!
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]

Yii2 SwiftMailer sending email via remote smtp server (gmail)

I want to send emails via my gmail account.
My mailer config:
[
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,//set this property to false to send mails to real email addresses
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'my#gmail.com',
'password' => 'pass',
'port' => '587',
'encryption' => 'tls',
],
]
I wrote command MailController:
<?php
namespace app\commands;
use yii\console\Controller;
use Yii;
/**
* Sanding mail
* Class MailController
* #package app\commands
*/
class MailController extends Controller
{
private $from = 'my#gmail.com';
private $to = 'to#gmail.com';
public function actionIndex($type = 'test', $data = null)
{
Yii::$app->mailer->compose($type, ['data' => $data])
->setFrom($this->from)
->setTo($this->to)
->setSubject($this->subjects[$type])
->send();
}
}
When I'm trying to run: php yii mail
I get: sh: 1: /usr/sbin/sendmail: not found
But why it requires sendmail if I want just SMTP connection to smtp.gmail.com?
I think you have configured the mailer wrongly. Because it is still using the default mail function. From the documentation the configuration should be like below. The mailer should be inside components.
'components' => [
...
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'username',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
...
],
One more suggestion is to use port "465" and encryption as "ssl" instead of port "587", encryption "tls".
Yii2 Has different config files for web and console works. So you need to config both of them. Regarding this issue, I had to make mail config file (for example mailer.php) and include it in both config files (web.php & console.php) like:
'components' => [
...
'mailer' => require(__DIR__ . '/mailer.php'),
...
],
Might be useful for someone as reference:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'username',
'password' => 'password',
'port' => 587,
'encryption' => 'tls',
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]
],
]