我需要在Microsoft服务器上安装PHP站点。由于某种原因,主持人不允许该网站发送电子邮件。主持人给我发了一个代码样本......但是没有用。
有没有办法检查服务器是否允许通过php mail()函数发送电子邮件?
在这个阶段,它完全是指责,我需要一些证据来向客户表明主机有问题。
答案 0 :(得分:3)
在Linux中,默认情况下mail()函数使用来自操作系统的sendmail。
在Windows中,默认情况下mail()不执行任何操作,您必须将其设置为编辑php.ini文件。
您可以查看您的主机正在使用的php.ini中的哪些选项,编写showinfo.php文件,并在其中写入:
<?php
phpinfo();
?>
然后,如果您调用该网页,它会显示所有已启用的选项。
为了能够在Windows上发送邮件,这两个值应该设置如下:
SMTP = smtp.isp.net (the name or ip of your server)
sendmail_from = me@isp.net
XAMPP平台附带了mailtodisk替换,您可以将其设置为使用“fakemail”代替sendmail,也可以通过SMTP连接。您可以使用XAMPP附带的sendmail文件夹,并在IIS使用的php.ini中进行设置。
答案 1 :(得分:1)
要检查是否已在服务器或PHP安装上启用了邮件功能,请使用
<?php
if ( function_exists( 'mail' ) )
{
echo 'mail() is available';
}
else
{
echo 'mail() has been disabled';
}
?>
检查它是否发送邮件
<?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
如果您在Linux上:
尝试;
$ dpkg -S `which sendmail`
在Ubuntu上安装sendmail;
sudo apt-get install sendmail
https://www.digitalocean.com/community/questions/setting-up-email-with-sendmail
答案 2 :(得分:-1)
This seems like an old post but you may use the function_exists() function, check if the function exist before using it.