【问题标题】:how to send email in php from localhost?如何在 php 中从 localhost 发送电子邮件?
【发布时间】:2014-03-06 16:58:09
【问题描述】:

我无法使用 php 脚本从本地主机发送电子邮件 这是我的代码

<?php

ini_set("SMTP","bhoi@gmail.com");

ini_set("smtp_port","25");

ini_set('sendmail_from', 'bhoi@gmail.com');

//define the receiver of the email
$to = 'deepan@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 World!\n\nThis is my first mail."; 

//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: bhoi@gmail.com\r\nReply-To: bhoi@gmail.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";

?>

php.ini 文件...

[邮件功能]

;仅适用于 Win32。

SMTP = 本地主机

smtp_port = 25

;仅适用于 Win32。

sendmail_from =bhoi@gmail.com

输出是“邮件失败”

请帮我解决我的问题。

【问题讨论】:

  • 我怀疑 bhoi.test@gmail 是一个 smtp 服务器

标签: php


【解决方案1】:

我会告诉你最简单的方法。

您可以使用开源 Papercut 并下载应用程序并运行它,而无需对 xampp php.inisendmail.ini 文件进行任何更改。然后当你在 php 中运行你的邮件时,你会直接将它放入剪纸应用程序中。这是一个很棒的应用程序,你不需要配置任何东西。

注意:请不要在 xampp 中进行任何更改,例如更改 smtp_server。保持默认的 xampp 设置即可。

【讨论】:

    【解决方案2】:

    我尝试了 Windows 的假 sendmail,它对我有用。你可以在这里查看。 http://glob.com.au/sendmail/ 之后,您必须将 php.ini 中的 sendmail_path 设置为硬盘上的 sendmail 路径。

    【讨论】:

      【解决方案3】:

      您需要安装 smtp 服务器或为公共邮件服务器设置配置

      看这个例子

      SMTP = smtp.yourdomain.com
      smtp_port = 25
      username = info@yourdomain.com
      password = yourmailpassord
      sendmail_from = info@yourdomain.com
      

      【讨论】:

      • 如何设置公共邮件服务器的配置?
      • 看看这个 [邮件功能] SMTP = ssl://smtp.gmail.com smtp_port = 465 用户名 = info@Mmydomainname.com 密码 = myemailpassword sendmail_from = info@mydomainname.com 或者你可以这样做:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-25
      • 1970-01-01
      • 2017-06-19
      • 2012-07-03
      • 2012-12-03
      • 1970-01-01
      • 2018-11-27
      相关资源
      最近更新 更多