简体   繁体   English

使用phpmailer yii2发送邮件

[英]send mail using phpmailer yii2

I have installed zyx-phpmailer extension for send mail function in yii2 and working properly. 我已经在yii2中安装了zyx-phpmailer扩展名来发送邮件功能并正常工作。 But, when i checked via yii debugger the recipient is empty . 但是,当我通过yii调试器检查时,收件人是empty If I using swiftmailer, there is no problem, but I must using zyx-phpmailer :( 如果我使用swiftmailer,没有问题,但我必须使用zyx-phpmailer :(

code : 代码:

Yii::$app->mailer->compose()
                 ->setTo('people@blabla.com')
                 ->setFrom('admin@example.com')
                 ->setSubject('Test')
                 ->send();

Result (yii debugger) : 结果(yii调试器):

From    : admin@example.com
To      : empty // <- this is a problem
Subject : Test
Text body   (not set)
Successfully sent   : Yes

How to solve this issue? 如何解决这个问题? I'm still learning using yii2 framework. 我还在学习使用yii2框架。

Check if your current mailer is actually the new extension and not SwiftMailer, you can trace it at runtime by calling this Yii::trace(Yii::$app->get('mailer')) . 检查您当前的邮件程序是否实际上是新的扩展名而不是SwiftMailer,您可以通过调用此Yii::trace(Yii::$app->get('mailer'))在运行时跟踪它。 Maybe you did not fully configure it. 也许你没有完全配置它。

Try ->setTo(['people@blabla.com' => 'People Blabla']) . 尝试->setTo(['people@blabla.com' => 'People Blabla']) The first one being the email address itself and the second one being the name. 第一个是电子邮件地址本身,第二个是名称。

it work;try 它工作;尝试

Yii::$app->mail->compose()
     ->setFrom(['xx@xx.com' => 'My Example Site'])
     ->setTo([$form->email => $form->name])
     ->setSubject($form->subject)
     ->setTextBody($form->text)
     ->send();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM