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

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

问题描述

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



我没有托管我的网站,所以它在本地主机上。
我设置了smtp,port sendmail_path等。



搜索很多我似乎需要下载一个邮件服务器。
我下载了一个免费的sendmail服务器,并将其配置为网站建议。
但是,所有这一切都是徒劳的,有人告诉我,我不能使用邮件功能,直到我托管我的网站不仅在本地主机。请指导我。

 <?php 
$ from =oooo@hotmail.com; // sender
$ subject =我的cron正在工作;
$ message =我的第一个Cron :);

//消息行不应超过70个字符(PHP规则),所以包装

$ message = wordwrap($ message,70);

//发送邮件

ini_set(SMTP,localhost);
ini_set(smtp_port,25);
ini_set(sendmail_from,00000@gmail.com);
ini_set(sendmail_path,C:\wamp\bin\sendmail.exe -t);

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

回显谢谢你给我们反馈;

?>

这是我的sendmail配置文件:

  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:
(!)警告:mail()[< a href ='function.mail'> function.mail< / a>]:无法连接到mailserver& quot; localhost&端口25,验证您的& quot; SMTP& quot;和& quot; smtp_port& quot;设置在php.ini或使用ini_set()在C:\wamp\www\test.php行20


解决方案

我认为您未正确配置



如果您使用XAMPP,那么您可以轻松地发送邮件来自localhost。



例如,您可以配置 C:\xampp\php\php.ini c:\xampp\sendmail\sendmail.ini 为gmail发送邮件。



in C:\xampp\php\php.ini 找到 extension = php_openssl.dll 并从头开始删除分号该行使SSL可以用于本地主机的gmail。



在php.ini文件中查找 [邮件功能] 并更改

  SMTP = smtp.gmail.com 
smtp_port = 587
sendmail_from = my-gmail- id@gmail.com
sendmail_path =\C:\xampp\sendmail\sendmail.exe\-t

现在打开 C:\xampp\sendmail\sendmail.ini 。用以下代码替换sendmail.ini中现有的所有代码

  [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文件,并从localhost发送邮件。



更新



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



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

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


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.

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

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:\wamp\bin\sendmail.exe -t");

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

   echo "Thank you for sending us feedback";

?>

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:\wamp\www\test.php on line 20

解决方案

I think you are not configured properly,

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

for example you can configure C:\xampp\php\php.ini and c:\xampp\sendmail\sendmail.ini for gmail to send mail.

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

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:\xampp\sendmail\sendmail.exe\" -t"

Now Open C:\xampp\sendmail\sendmail.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

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

Update

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

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天全站免登陆