【问题标题】:Intercept all emails sent from Xampp Mercury Mail Server拦截从 Xampp Mercury Mail Server 发送的所有电子邮件
【发布时间】:2015-02-27 22:41:16
【问题描述】:
我有一个仅在开发环境中使用的 Xampp 服务器。为了预览将从实时站点发送的电子邮件而不实际发送它们,我想拦截从该服务器发送的所有电子邮件。我希望能够将它们全部发送到特定的电子邮件或将它们保存为文件,而不是将它们发送到他们设置的任何地址。这样我就可以确保它们是正确的,而不会在测试期间意外发送电子邮件。


我发现了一个类似的问题的答案 here 但无法找到打开答案中任何对话框的方法,因此并没有让我走得太远。


在此先感谢您的帮助!

【问题讨论】:

    标签: email xampp mail-server


    【解决方案1】:

    您可以使用 php.ini 中的 sendmail 配置来完成此操作。

    创建一个名为smtp_catcher.php的文件并设置sendmail_path

    sendmail_path = "php C:\path\to\file\smtp_catcher.php"
    

    然后在您的smtp_catcher.php 中添加此块:

    #!/Applications/XAMPP/xamppfiles/bin
    <?php
    
    # create a filename for the emlx file
    list($ms, $time) = explode(' ', microtime());
    $filename = dirname(__FILE__).'/'.date('Y-m-d h.i.s,', $time).substr($ms,2,3).'.emlx';
    
    # write the email contents to the file
    $email_contents = fopen('php://stdin', 'r');
    $fstat = fstat($email_contents);
    file_put_contents($filename, $fstat['size']."\n");
    file_put_contents($filename, $email_contents, FILE_APPEND);
    
    # open up the emlx file (using Apple Mail)
    exec('open '.escapeshellarg($filename));
    
    ?>
    

    现在我不确定您需要使用什么扩展程序来查看电子邮件,但这应该可以捕获所有发出的电子邮件。

    注意:确保 php 在您窗口的环境路径中

    【讨论】:

    • 注意,如果php不在我们window的环境路径中,添加后可能需要重启电脑才能生效。
    猜你喜欢
    • 2011-09-20
    • 2013-06-04
    • 2014-10-25
    • 2015-10-26
    • 1970-01-01
    • 2018-03-08
    • 2014-10-03
    • 2011-04-22
    • 1970-01-01
    相关资源
    最近更新 更多