从 localhost 测试 PHP 的邮件功能 [英] Test PHP's mail function from localhost

查看:25
本文介绍了从 localhost 测试 PHP 的邮件功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试一个使用 PHP 的 mail() 的函数
如何在不将脚本上传到服务器并在线测试的情况下执行此操作?
更重要的是,我在完全没有互联网连接的情况下进行开发.
我在 Mac OSX 上从 XAMPP 运行 localhost.

I need to test a function that uses PHP's mail()
How can I do this without uploading the script to a server and test it online?
What's even more I am developing with no Internet connection at all.
I am on Mac OSX running localhost from XAMPP.

推荐答案

您不必在计算机上安装 MTA 来测试 PHP 的 mail() 功能.在基于 Unix 的系统(Linux、*BSD、OS X 等)上,您可以将 sendmail_path 设置为类似 tee mail.out > 的内容./dev/null.这会将电子邮件(包括标题)放入名为 mail.out 的文件中.

You don't have to install an MTA on your computer to test PHP's mail() function. On Unix based systems (Linux, *BSD, OS X, etc.) you can set sendmail_path to something like tee mail.out > /dev/null. This will put the emails (including the headers) in a file called mail.out.

以下是它如何工作的示例:

Here is an example of how it would work:

daniel@daniel-laptop:~$ cat | php -d sendmail_path='tee mail.out > /dev/null'
<?php
mail('test@example.com', 'the subject', 'the body');
?>
daniel@daniel-laptop:~$ cat mail.out
To: test@example.com
Subject: the subject
X-PHP-Originating-Script: 1000:-


the body

您可以在 php.ini 文件中设置 sendmail_path.如果您想将电子邮件附加到文件而不是每次都覆盖,您可以使用 tee -a 而不是 tee.

You can set sendmail_path in your php.ini file. If you want to append emails to the file instead of overwriting each time, you can use tee -a instead of just tee.

这篇关于从 localhost 测试 PHP 的邮件功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆