Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查是否启用了PHP mail()?_Php_Email - Fatal编程技术网

如何检查是否启用了PHP mail()?

如何检查是否启用了PHP mail()?,php,email,Php,Email,我需要在Microsoft服务器上安装一个PHP站点。出于某种原因,主机不允许站点发送电子邮件。主机已向我发送了一个代码示例。。。这没用 有没有办法检查服务器是否允许通过php mail()函数发送电子邮件 在这个阶段,一切都是关于指责,我需要一些证据来向客户机表明主机出了问题。在Linux中,默认情况下,mail()函数使用操作系统中的sendmail 在Windows中,默认情况下mail()不做任何事情,您必须设置它来编辑php.ini文件 您可以检查主机使用的php.ini中的选项,编写

我需要在Microsoft服务器上安装一个PHP站点。出于某种原因,主机不允许站点发送电子邮件。主机已向我发送了一个代码示例。。。这没用

有没有办法检查服务器是否允许通过php mail()函数发送电子邮件

在这个阶段,一切都是关于指责,我需要一些证据来向客户机表明主机出了问题。

在Linux中,默认情况下,mail()函数使用操作系统中的sendmail

在Windows中,默认情况下mail()不做任何事情,您必须设置它来编辑php.ini文件

您可以检查主机使用的php.ini中的选项,编写showinfo.php文件,并在其中写入:

   <?php
   phpinfo();
   ?>

XAMPP平台附带了一个mailtodisk替换,您可以将其设置为使用“fakemail”代替sendmail,也可以通过SMTP连接。您可以使用XAMPP附带的sendmail文件夹,并在IIS使用的php.ini中设置它。

这似乎是一篇旧文章,但您可以使用函数_exists()函数,在使用它之前检查该函数是否存在。

要检查您的服务器或php安装上是否启用了mail函数,请使用

<?php
if ( function_exists( 'mail' ) )
{
    echo 'mail() is available';
}
else
{
    echo 'mail() has been disabled';
}
?>
在Ubuntu上安装sendmail

sudo apt-get install sendmail

在将问题发布到此处之前,您是否尝试过该功能?该函数将存在,因为PHP 4。因此,这不是一个解决方案。
<?php 

$email = "youremail@gmail.com";
$subject =  "Email Test";
$message = "this is a mail testing email function on server";


$sendMail = mail($email, $subject, $message);
if($sendMail)
{
echo "Email Sent Successfully";
}
else

{
echo "Mail Failed";
}
?>

If the mail() function exist but mails not going, check if a mail transport agent (MTA)such as sendmail or postfix is installed on your server
$ dpkg -S `which sendmail`
sudo apt-get install sendmail