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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题