如何在 Yii2 应用程序中使用 Swiftmailer 发送经过身份验证的电子邮件?

问题描述

我需要告诉 SwiftMailer 要求进行身份验证才能从我的网站发送电子邮件。 我已经搜索了几天,但找不到要指定的参数。

我的托管公司说我必须使用 Pear 来做这件事,但我想 yii 会处理它。

我的设置是

'mailer' => [
            'class' => 'yii\swiftmailer\Mailer','viewPath' => '@common/mail','useFileTransport' => false,'transport' => [
                'class' => 'Swift_SmtpTransport','encryption' => 'tls','host' => 'lss1.layerip.com','port' => '465','username' => xxx@yyy.com','password' => ppppp

我正在使用高级应用程序,而托管服务提供商对我来说是新手 (Jolt)。

这是他们推荐的:


    <?PHP
      require_once "check_the_correct_path_above/Mail.PHP";
      $from = "Sandra Sender <sender@example.com>";
      $to = "Ramona Recipient <recipient@example.com>";
      $subject = "Hi!";
      $body = "Hi,\n\nHow are you?";
      $host = "ssl://mail.example.com";
      $port = "465";
      $username = "smtp_username";
      $password = "smtp_password";
      $headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
      
      $smtp = Mail::factory('smtp',array ('host' => $host,'port' => $port,'auth' => true,'username' => $username,'password' => $password));
      
      $mail = $smtp->send($to,$headers,$body);
      
      if (PEAR::isError($mail)) {
        echo("<p>" . $mail->getMessage() . "</p>");
       } else {
        echo("<p>Message successfully sent!</p>");
       }
      ?>

解决方法

您能否提供发送时收到的错误信息?

请在您的配置文件中发送 swiftmail 配置。我想看看你的

filetransport

定义。