duanlinghe8417 2013-12-17 17:36
浏览 47
已采纳

在SwiftMailer中检索SMTP会话

I am using SwiftMailer to send emails and my site is all of a sudden having timeout issues when trying to send an email.

I need to extract the "SMTP conversation" so my host can debug it.

Is there any code that can give me this?

include('SwiftMailer/swift_required.php');
$transport = Swift_SmtpTransport::newInstance('smtp.example.com', 587);
$transport->setUsername('username');
$transport->setPassword('password');
$swift = Swift_Mailer::newInstance($transport);

// Create a message
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($message, $content_type, SITE_CHARSET);
$message->setTo($to);

try {
    $swift->send($message);
} catch (Swift_TransportException $e) {
    // Log array for further inspection
}
  • 写回答

2条回答 默认 最新

  • dounaidu0204 2013-12-17 17:41
    关注

    You might want to take a look at the SwiftMailer Logger Plugin which will allow you log all the interactions between your client and the SMTP server.

    There is two types of loggers available:

    • The ArrayLogger - (Keeps a collection of log messages inside an array. The array content can be cleared or dumped out to the screen)
    • The EchoLogger (Prints output to the screen in realtime. Handy for very rudimentary debug output)

    You can register the plugin using either:

    $logger = new Swift_Plugins_Loggers_ArrayLogger();
    $swift->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
    

    or

    $logger = new Swift_Plugins_Loggers_EchoLogger();
    $swift->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
    

    Just make sure you have the plugin installed and that your class autoloader can access the required class on demand.

    Refer to the documentation for further details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?