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 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀