【问题标题】:Swift Mailer does not work and gives no error messagesSwift Mailer 不工作并且没有给出错误信息
【发布时间】:2020-04-18 14:24:04
【问题描述】:

我尝试通过 Swift-Mailer 发送电子邮件。根据文档,它应该像这样工作,但我既没有收到邮件也没有收到错误消息。

这是 PHP Swift 文件的代码:

<?php
    require_once '/composer/vendor/autoload.php';

    // Create the Transport
    $transport = (new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
    ->setUsername('*******@gmail.com')
    ->setPassword('password')
    ;

    // Create the Mailer using your created Transport
    $mailer = new Swift_Mailer($transport);

    // Create a message
    $message = (new Swift_Message('Wonderful Subject'))
    ->setFrom(['john@doe.com' => 'John Doe'])
    ->setTo(['infinity.community.work@gmail.com', 'other@domain.org' => 'A name'])
    ->setBody('Here is the message itself')
    ;

    // Send the message
    $result = $mailer->send($message);
?>

这里是composer.json:

{
    "require": {
        "swiftmailer/swiftmailer": "^6.0"
    }
}

【问题讨论】:

    标签: php gmail swiftmailer


    【解决方案1】:

    使用此语法再次检查并确保电子邮件或密码拼写正确:

    $trp = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
            ->setUsername('*********@gmail.com')
            ->setPassword('password');
    
    $mailer = Swift_Mailer::newInstance($trp);
    
    $message = Swift_Message::newInstance('Wonderful Subject')
        ->setFrom(['john@doe.com' => 'John Doe'])
        ->setTo(['infinity.community.work@gmail.com', 'other@domain.org' => 'A name'])
        ->setBody('Here is the message itself');
    
    $mailer->send($message);
    

    编辑: 与 SwiftMailer 版本 5.4 成功配合

    【讨论】:

    • 不幸的是,在创建新的 Swift_SmtpTransport 实例时,PHP 页面直接崩溃。
    • 好的,我会试试的。
    • 版本 5.6 不可用,但我尝试了 5.4.9 并且它可以工作,谢谢
    猜你喜欢
    • 1970-01-01
    • 2014-09-30
    • 2022-01-17
    • 2011-05-16
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 2014-12-10
    相关资源
    最近更新 更多