php函数mail()不起作用 [英] php function mail() isn't working

查看:27
本文介绍了php函数mail()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 php 编码中使用了 mail() 函数,但我没有发送任何邮件.在继续之前,我想详细说明使用 mail() 函数的上下文.

I used mail() function in php coding but I failed to send any mail. Before proceeding ahead I want to elaborate the context of using the mail() function.

我没有托管我的网站,所以它位于本地主机上.我确实设置了 smtp、端口 sendmail_path 等.

I didnt host my site so it is on localhost. I did set smtp, port sendmail_path etc.

经过大量搜索,我似乎需要下载一个邮件服务器.我下载了一个免费的 sendmail 服务器,并按照网站的建议对其进行了配置.然而,一切都是徒劳的,而且有人告诉我,在我不仅在本地主机上托管我的网站之前,我不能使用邮件功能.请指导我.

After searching a lot I it seems that I need to download a mail server. I downloaded a sendmail server that is free and configured it as the site suggested. However, all in vain moreover, someone told me that I can't use mail function until I host my site not only on localhost. Please guide me.

<?php
   $from = "oooo@hotmail.com"; // sender
   $subject = " My cron is working";
   $message = "My first Cron  :)";

   // message lines should not exceed 70 characters (PHP rule), so wrap it

   $message = wordwrap($message, 70);

   // send mail

   ini_set("SMTP","localhost");
   ini_set("smtp_port","25");
   ini_set("sendmail_from","00000@gmail.com");
   ini_set("sendmail_path", "C:wampinsendmail.exe -t");

   mail("jXXXXXX@gmail.com",$subject,$message,"From: $from
");

   echo "Thank you for sending us feedback";

?>

这是我的 sendmail 配置文件:

this my sendmail configuration file:

smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto

;default_domain=domain.com
auth_username=jxxxx@gmail.com
auth_password=8888

force_sender=j*****@gmail.com

( ! ) SCREAM: Error suppression ignored for
( ! ) Warning: mail() [<a href='function.mail'>function.mail</a>]: Failed to connect to      mailserver at &quot;localhost&quot; port 25, verify your &quot;SMTP&quot; and &quot;smtp_port&quot;    setting in php.ini or use ini_set() in C:wampwww	est.php on line 20

推荐答案

我觉得你配置不正确,

如果您使用的是 XAMPP,那么您可以轻松地从 localhost 发送邮件.

if you are using XAMPP then you can easily send mail from localhost.

例如,您可以配置 C:xamppphpphp.inic:xamppsendmailsendmail.ini 让 gmail 发送邮件.

for example you can configure C:xamppphpphp.ini and c:xamppsendmailsendmail.ini for gmail to send mail.

C:xamppphpphp.ini 中找到 extension=php_openssl.dll 并从该行的开头删除分号以使 SSL 适用于 gmail对于本地主机.

in C:xamppphpphp.ini find extension=php_openssl.dll and remove the semicolon from the beginning of that line to make SSL working for gmail for localhost.

在php.ini文件中找到[mail function]并修改

in php.ini file find [mail function] and change

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "C:xamppsendmailsendmail.exe -t"

(仅使用上述发送邮件路径即可)

(use the above send mail path only and it will work)

现在打开 C:xamppsendmailsendmail.ini.将 sendmail.ini 中的所有现有代码替换为以下代码

Now Open C:xamppsendmailsendmail.ini. Replace all the existing code in sendmail.ini with following code

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com

现在你已经完成了!创建带有邮件功能的php文件并从本地主机发送邮件.

Now you have done!! create php file with mail function and send mail from localhost.

更新

首先,确保您的 PHP 安装支持 SSL(在 phpinfo() 的输出中查找openssl"部分).

First, make sure you PHP installation has SSL support (look for an "openssl" section in the output from phpinfo()).

您可以在 PHP.ini 中设置以下设置:

You can set the following settings in your PHP.ini:

ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");

这篇关于php函数mail()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆