从yii2中的其他smtp发送电子邮件

时间:2016-06-06 07:35:49

标签: yii2 swiftmailer

我使用swiftmailer从yii2发送电子邮件。我从网站获取代码,但大多数都是从gmail.com发送电子邮件。我想从我的大学电子邮件发送电子邮件,但它不起作用。有什么问题。这是代码:

在main-local.php中

'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => /*true*/false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.students.del.ac.id',
                'username' => 'if414024@students.del.ac.id',
                'password' => 'bmelar28',
                'port' => '587',
                'encryption' => 'tls',
            ],
],

2 个答案:

答案 0 :(得分:1)

删除smtp

中的'host' => students.del.ac.id

显示以下代码

'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        'useFileTransport' => false,
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'students.del.ac.id',
            'username' => 'if414024@students.del.ac.id',
            'password' => 'bmelar28',
            'port' => '587',
            'encryption' => 'tls',                               
        ]
]

答案 1 :(得分:0)

试试这个:更改端口号和主机

'mailer' => [
                'class' => 'yii\swiftmailer\Mailer',
                'viewPath' => '@common/mail',
                // send all mails to a file by default. You have to set
                // 'useFileTransport' to false and configure a transport
                // for the mailer to send real emails.
                'useFileTransport' => /*true*/false,
                'transport' => [
                    'class' => 'Swift_SmtpTransport',
                    'host' => 'students.del.ac.id',
                    'username' => 'if414024@students.del.ac.id',
                    'password' => 'bmelar28',
                    'port' => '25',
                    'encryption' => 'tls',
                ],
    ],