在yii2高级模板中注册时发生Swift_TransportException错误

时间:2019-05-31 07:20:53

标签: yii2-advanced-app

我正在使用yii2高级模板,并在注册发送电子邮件时遇到问题。 我已经使用mailtraf发送电子邮件,并在common / config / mainlocal-php中包含了所有详细信息。

maillocal.php看起来像:

<?php
return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=advanced_yii2',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
        ],
        'mail' => [
        'class' => 'yii\swiftmailer\Mailer',
                'viewPath' => '@common/mail',
                'useFileTransport' => false,
                'transport' => [
                    'class' => 'Swift_SmtpTransport',
                    'host' => 'smtp.mailtrap.io',
                    'username' => '9**************e',
                    'password' => '7***************5',
                    'port' => '2525',
                    'encryption' => 'tls',
            ],
    ],
    ],
];

This is the error i am getting.

Swift_TransportException
Process could not be started [The system cannot find the path specified.
]
1. in C:\xampp\htdocs\yii-application\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php at line 299
2. in C:\xampp\htdocs\yii-application\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php at line 54 – Swift_Transport_StreamBuffer::establishProcessConnection()
3. in C:\xampp\htdocs\yii-application\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php at line 143 – Swift_Transport_StreamBuffer::initialize(['timeout' => 30, 'blocking' => 1, 'command' => '/usr/sbin/sendmail -bs', 'type' => 16])
4. in C:\xampp\htdocs\yii-application\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\SendmailTransport.php at line 50 – Swift_Transport_AbstractSmtpTransport::start()
5. in C:\xampp\htdocs\yii-application\vendor\yiisoft\yii2-swiftmailer\src\Mailer.php at line 113 – Swift_Transport_SendmailTransport::start()
6. in C:\xampp\htdocs\yii-application\vendor\yiisoft\yii2-swiftmailer\src\Mailer.php at line 156 – yii\swiftmailer\Mailer::getSwiftMailer()
7. in C:\xampp\htdocs\yii-application\vendor\yiisoft\yii2\mail\BaseMailer.php at line 263 – yii\swiftmailer\Mailer::sendMessage(yii\swiftmailer\Message)
8. in C:\xampp\htdocs\yii-application\vendor\yiisoft\yii2\mail\BaseMessage.php at line 49 – yii\mail\BaseMailer::send(yii\swiftmailer\Message)
9. in C:\xampp\htdocs\yii-application\frontend\models\SignupForm.php at line 77 – yii\mail\BaseMessage::send()
10. in C:\xampp\htdocs\yii-application\frontend\models\SignupForm.php at line 57 – frontend\models\SignupForm::sendEmail(common\models\User)
11. in C:\xampp\htdocs\yii-application\frontend\controllers\SiteController.php at line 156 – frontend\models\SignupForm::signup()
12. frontend\controllers\SiteController::actionSignup()
13. in C:\xampp\htdocs\yii-application\vendor\yiisoft\yii2\base\InlineAction.php at line 57 – call_user_func_array([frontend\controllers\SiteController, 'actionSignup'], [])
14. in C:\xampp\htdocs\yii-application\vendor\yiisoft\yii2\base\Controller.php at line 157 – yii\base\InlineAction::runWithParams(['r' => 'site/signup'])
15. in C:\xampp\htdocs\yii-application\vendor\yiisoft\yii2\base\Module.php at line 528 – yii\base\Controller::runAction('signup', ['r' => 'site/signup'])
16. in C:\xampp\htdocs\yii-application\vendor\yiisoft\yii2\web\Application.php at line 103 – yii\base\Module::runAction('site/signup', ['r' => 'site/signup'])
17. in C:\xampp\htdocs\yii-application\vendor\yiisoft\yii2\base\Application.php at line 386 – yii\web\Application::handleRequest(yii\web\Request)
18. in C:\xampp\htdocs\yii-application\frontend\web\index.php at line 17 – yii\base\Application::run()

2 个答案:

答案 0 :(得分:0)

我认为在mail中存在问题,您应该使用mailer嵌套的mail

例如:

'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'localhost',
                'username' => 'username',
                'password' => 'password',
                'port' => '587',
                'encryption' => 'tls',
            ],
        ],

这是documentation

答案 1 :(得分:0)

我已经通过我的swiftmailer帐户测试了此设置,并且可以确认通过注册提交的注册电子邮件已到达在注册下输入的电子邮件帐户。因此,通过下面设置的mailtrap帐户进行操作并成功完成。我通常使用在宽带提供商下设置的虚拟帐户,以便绕过设置困难的hmailserver。我通常使用端口25通过宽带提供商进行连接,因此我决定也将端口25用于邮件陷阱。

    <?php
    'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'enableSwiftMailerLogging' =>false,
            //set useFileTransport to true to send to log file
            'useFileTransport' => false,
            'transport' => ['class' => 'Swift_SmtpTransport',
                            'host' => 'smtp.mailtrap.io',
                           'username' => 'f8b66f8dc0eac1',
                            'password' => 'd5da52313fcdd9',
                            'port' => '25',
                           //'encryption' => 'tls',
                           ] 
            ],
            ?>

顺便说一句,我正在使用sjaak / pluto进行注册,并对这个新模块非常满意。