简体   繁体   English

PHP邮件错误报告

[英]PHP mail Error Reporting

I have the following code to test if the website can send mail via php: 我有以下代码来测试网站是否可以通过php发送邮件:

<?php 
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "emailtest@YOURDOMAIN";
$to = "YOUREMAILADDRESS";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";
?>

I have uploaded this php file to www.mywebsite.com/data/iq/testing-email.php 我已将此php文件上传到www.mywebsite.com/data/iq/testing-email.php

when I run the script I get the following error: 当我运行脚本时,出现以下错误:

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\\mywebsite.com\\data\\iq\\test-email.php on line 9 警告:mail():无法通过“ localhost”端口25连接到邮件服务器,无法验证php.ini中的“ SMTP”和“ smtp_port”设置,或在C:\\ mywebsite.com \\ data \\ iq \\ test中使用ini_set() -email.php在第9行

My question is why is the error showing a C:\\ file directory when the website is already live? 我的问题是,当网站已经启用时,为什么错误显示C:\\文件目录?

For reference this website is running on a Microsoft IIS Server and has an SSL if that makes any difference. 作为参考,该网站在Microsoft IIS服务器上运行,并具有SSL(如果有区别)。

When you use mail() your PHP script tries to connect to an external SMTP to deliver your email, so you must configure a valid one. 当您使用mail()时,您的PHP脚本会尝试连接到外部SMTP来发送您的电子邮件,因此您必须配置一个有效的电子邮件。

By default it tries to connect to localhost, but the webserver apparently is not running an SMTP server, so you should ask your provider for the correct SMTP to use, and set it with: 默认情况下,它尝试连接到本地主机,但是Web服务器显然未运行SMTP服务器,因此您应该向提供商咨询要使用的正确SMTP,并使用以下命令进行设置:

ini_set('SMTP','smtp.yourprovider.cxm');
ini_set('smtp_port',25);

About your second question, C:\\mywebsite.com\\ is probably the server folder where your files are hosted, so it looks very normal to me. 关于您的第二个问题,C:\\ mywebsite.com \\可能是文件所在的服务器文件夹,因此对我来说似乎很正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM