Php 从Yii2和wampserver 2.5发送电子邮件

Php 从Yii2和wampserver 2.5发送电子邮件,php,email,wampserver,yii2,Php,Email,Wampserver,Yii2,在我的项目中,我将Yi2与WAMPServer2.5结合使用。我正在尝试做的是相当基本的:我只需要能够从我的本地机器发送电子邮件 我尝试过互联网上的各种教程和操作指南,到目前为止还没有一本有效。我正在尝试使用swiftmailer,它包含在Yii2中的smtp.gmail.com中 如果有人使用这种组合(Yii2和wampserver 2.5)能在这里帮助我,我将不胜感激。我使用带有Yii2和swiftmailer扩展的xampp服务器。我将swiftmailer配置为使用gmail作为smtp

在我的项目中,我将Yi2与WAMPServer2.5结合使用。我正在尝试做的是相当基本的:我只需要能够从我的本地机器发送电子邮件

我尝试过互联网上的各种教程和操作指南,到目前为止还没有一本有效。我正在尝试使用swiftmailer,它包含在Yii2中的smtp.gmail.com中


如果有人使用这种组合(Yii2和wampserver 2.5)能在这里帮助我,我将不胜感激。

我使用带有Yii2和swiftmailer扩展的xampp服务器。我将swiftmailer配置为使用gmail作为smtp发送邮件。以下是我的代码

在common/main-local.php的组件部分

'mail' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@backend/mail',
        'useFileTransport' => false,//to send mails to real email addresses else will get stored in your mail/runtime folder
        //comment the following array to send mail using php's mail function
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.gmail.com',
            'username' => 'username@gmail.com',
            'password' => 'password',
            'port' => '587',
            'encryption' => 'tls',
                        ],
    ],
    ],
在控制器中

    \Yii::$app->mail->compose('your_view', ['params' => $params])
    ->setFrom([\Yii::$app->params['supportEmail'] => 'Test Mail'])
    ->setTo('to_email@xx.com')
    ->setSubject('This is a test mail ' )
    ->send();

这应该管用!希望这对你有帮助

Stackoverflow不会取代谢谢,但这是yii 1.1。如标题和帖子所述,这是指yii2。太棒了,谢谢。我会试试看。您是否必须在xampp中执行任何操作才能使其正常工作?smtp与xampp服务器无关,它将使用gmail服务器和access发送电子邮件。但是你可能需要在你将要使用的gmail帐户上设置较低的安全设置。