yiisoft/yii2-symfonymailer

No Email sent, no error, send() returns true

1Luc1 opened this issue · 4 comments

1Luc1 commented

What steps will reproduce the problem?

config/web.php :

$config = [
   ...
   'components' => [
      ...
      'mailer' => require(__DIR__ . '/mailer.php'),
      ...
   ],
   ...
]

config/mailer.php :

<?php

$params = require(__DIR__ . '/params.php');

return [
    'class' => \yii\symfonymailer\Mailer::class,
    'transport' => [
        'host' => 'smtp.gmail.com',
        'username' => $params['adminEmail'],
        'password' => '********',
        'port' => '465',
        'options' => ['ssl' => true],
    ],
    'messageConfig' => [
        'from' => $params['adminEmail'], //'bcc' => '<bbc email>',
    ],
];

Method to send email:

public function sendEmail() {
    $mailer = Yii::$app->mailer;
    $oldViewPath = $mailer->viewPath;
    $mailer->viewPath = "@app/mail";
    $isSent = $mailer->compose('testEmail')
                    ->setTo($this->email)
                    ->setSubject(Yii::t('dev', 'Email Test Send'))
                    ->send();
    
    $mailer->viewPath = $oldViewPath;
    return $isSent;
}

$this->email comes from a form

What's expected?

Email will be send. ->send() method returns true.

What do you get instead?

Email won't be send. -> send() method returns true.

Additional info

Q A
Yii version 2.0.44
Yii SymfonyMailer version 2.0.0
SymfonyMailer version 6.0.2
PHP version 8.0.13
Operating system Manjaro

I switched from yiisoft/yii2-swiftmailer": "~2.1.2 . Sending email with swiftmailer worked.
Do I miss additional configuration? As stated from my config I'm trying to send from/over gmail account.

I apologize, I made a mistake in the implementation of logging, I will correct myself.

Pay attention to the configuration example in the README.MD you don't have the 'scheme' parameter specified.
'scheme' => 'smtp' or 'scheme' => 'smtps'

#13

1Luc1 commented

Thanks for the hint. I'll try it as soon as I'm at home.

About the scheme config, is there any further reading about the values which can be set? Could't find anything. Maybe to add some usefull link or info about it to the readme?

https://github.com/symfony/symfony-docs/blob/5.4/mailer.rst

Transport can be created in different ways

  1. Configure it yourself by implementing Symfony\Component\Mailer\Transport\TransportInterface
  2. In the configuration, set the dsn parameter from Symfony-docs, for example, in your case, you can use 'dsn' => 'gmail+smtp://USERNAME:PASSWORD@default'
  3. In the configuration, set all params for create DSN
[
  string $scheme,
  string $host,
  string $user = null,
  string $password = null,
  int $port = null,
  array $options = []
]

If we consider what is presented in the documentation then the options are
Built-in Transports

null
native
sendmail
smtp

3rd Party Transport

ses+smtp
ses+https
ses+api
gmail+smtp
mandrill+smtp
mandrill+https
mandrill+api
mailgun+smtp
mailgun+https
mailgun+api
mailjet+smtp
mailjet+api
postmark+smtp
postmark+api
sendgrid+smtp
sendgrid+api
sendinblue+smtp
sendinblue+api
ohmysmtp+smtp
ohmysmtp+api

I've tagged 2.0.1.