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

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

问题描述

我需要测试使用PHP邮件的功能()

如何将脚本上传到服务器并在线测试?

什么是甚么更多我正在开发没有互联网连接。

我在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() / code>函数。在基于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

您可以设置 sendmail_path 在您的 php.ini 文件中。如果要将邮件附加到文件中,而不是每次覆盖,可以使用 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天全站免登陆