如何使用 Windows 机器上的 PHP 将日志文件邮寄给自己?

How to mail a log file to yourself using PHP from a Windows machine ?

情况:

除此之外,我想在每次脚本 运行s.

通过电子邮件 自己发送该日志文件

我在脚本底部的某处试过这个:

mail('email@gmail.com', 'Report', strip_tags($response). PHP_EOL );

脚本 运行 一直到底部,我生成了日志文件,我也得到了 CLI 报告,但我 从来没有 收到任何电子邮件。

结果:

我不确定是因为我 :

有人可以帮助澄清这个问题吗?

您需要一个在 PHP.ini 中配置的邮件服务器来发送您的邮件。

这是一个简短的教程:

http://geekswithblogs.net/tkokke/archive/2009/05/31/sending-email-from-php-on-windows-using-iis.aspx

请注意,邮件服务器仍然需要 IIS6 控制台,如果您在 >=IIS7 上托管也是如此。

您还需要确保您的邮件服务器已被您要将此邮件发送到的邮件服务器接受。这绝对不是一项简单的任务。例如 Gmail 和 GMX 永远不会接受它,如果你没有 Reverse DNS 正确配置。

如果您不知道如何操作,我强烈建议您与您的系统管理员交谈。邮件服务器很难正确设置。这是我解决的任务。

但如果您不想配置自己的邮件服务器,这里有一个好消息。如果您使用开源项目 PHPMailer:

,使用托管电子邮件地址和 SMTP 非常简单
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

//More in the Documentation    

它有一个强大的 SMTP Class,这有助于极端登录任何 SMTP 帐户(例如 Gmail)。