Why emails are not sending from my website?

114 Views Asked by At

I am facing issue while sending email using Yii2 swiftmailer. I can't forward emails from my website.

'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            'transport' => [
 'class' => 'Swift_SmtpTransport',
                'host' => 'smtpout.secureserver.net',
                'username' => '[email protected]',
                'password' => 'mypassword',
                'port' => '465',
                'encryption' => 'ssl',
            ],
            'useFileTransport' => true,
        ],

What should I do for it?

I can't figure out what to do.

3

There are 3 best solutions below

0
DarkShade On

any error message? 'enableSwiftMailerLogging' => true, You can write and view the error log using the.

If it is giving error with ssl, you can get rid of ssl error by below code

'transport' => [
    'class' => 'Swift_SmtpTransport',
    'host' => 'smtpout.secureserver.net',
    'username' => '[email protected]',
    'password' => 'mypassword',
    'port' => '465',
    'encryption' => 'ssl',
    'streamOptions' => [
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ],
    'streamOptions' => ['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]],
    'streamOptions' => ['ssl' => ['allow_self_signed' => true]],
    'streamOptions' => ['ssl' => ['verify_depth' => false]],
],
'enableSwiftMailerLogging' => true,

Setting verify_peer to false can potentially expose your application to security risks, as it disables the verification of the peer's SSL/TLS certificate.

0
Senthil On

It's probably because you have useFileTransport set to true. If you set it to True the email messages will be saved as files under $fileTransportPath instead of sending them to the actual recipients.

0
Hemangi khatri On

Please use the 'useFileTransport' option set as false. You set it as true This means emails will not be sent via the SMTP server but saved in the file system under the runtime/mail directory. This could be the reason why your email is not being sent.