php函数mail()不起作用

2024-08-23php开发问题
17

本文介绍了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()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17