【问题标题】:php mail function..... Iam getting output as "mail failed". can you please help me to get it donephp 邮件功能.....我将输出为“邮件失败”。你能帮我完成吗
【发布时间】:2010-12-22 07:36:00
【问题描述】:
<?php
//define the receiver of the email
$to = 'pradz39@gmail.com';
//define the subject of the email
$subject = 'Test email';
//define the message to be sent. Each line should be separated with \n
$message = "Hello";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//send the email
$mail_sent = mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

我正在使用 xampp for windows 你能帮我配置 smtp 服务器吗.....

输出是

警告:mail() [function.mail]:无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或在 D:\installed 中使用 ini_set() \xampp\htdocs\mail.php 在第 13 行 邮件失败

【问题讨论】:

标签: php email


【解决方案1】:

PHP mail() 需要一个邮件中继服务器来实际发送邮件。在托管服务提供商上,环境已预先配置好并可供使用。

这些是您可能的解决方案。

  • 在您的情况下,您必须检查您的 xampp 捆绑包是否带有邮件服务器并设置/启动它
  • 如果它没有附带邮件服务器,那么您需要在http://support.microsoft.com/kb/230235 设置您的 IIS SMTP 服务器说明
  • 或下载并安装免费的 smpt 服务器,如 Argosoft
  • 您还可以使用可以直接连接到具有身份验证支持的 SMTP 的 php 包,并使用您的真实 smpt 服务器(hotmail、yahoo 等、isp)进行中继。这可以通过PHPMailer 完成,它也对我有用。

【讨论】:

    【解决方案2】:

    尝试删除“@”。 我已经尝试过这个示例代码,我在其中从输入表单中获取数据。 还有另一种方法,使用 SMTP,如果您知道 SMTP 服务器凭据,您也可以使用该方法。 这是示例;

    【讨论】:

      【解决方案3】:

      确保php.ini 文件中的 sendmail 设置正确。假设您正在运行 *nix:

      SMTP = myserver.localnet.com   
      sendmail_from = me@localhost.com  
      sendmail_path = /usr/sbin/sendmail
      

      mail() 有一些“陷阱”。请参阅此StackOverflow post 了解更多信息。

      【讨论】:

        【解决方案4】:

        这取决于很多环境,比如我的网站所在的位置,我猜邮件功能被禁用并且不起作用。所以,我使用 SMTP 并为企业使用谷歌邮件服务。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-07-25
          相关资源
          最近更新 更多