我在php编码中使用了mail()函数但是我没有发送任何邮件.在继续之前,我想详细说明使用mail()函数的上下文.
我没有托管我的网站,所以它在localhost上.我确实设置了smtp,端口sendmail_path等.
经过大量搜索后,我似乎需要下载邮件服务器.我下载了一个免费的sendmail服务器,并将其配置为网站建议.然而,一切都是徒劳的,有人告诉我,我不能使用邮件功能,直到我不仅在localhost上托管我的网站.请指导我.
<?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";
?>
Run Code Online (Sandbox Code Playgroud)
这是我的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: Error suppression ignored for
( ! ) Warning: mail() [<a href='function.mail'>function.mail</a>]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\test.php on line 20
Run Code Online (Sandbox Code Playgroud)
ɹɐq*_*ɹǝɟ 23
我认为你没有正确配置,
如果您使用XAMPP,那么您可以轻松地从localhost发送邮件.
例如,您可以配置C:\xampp\php\php.ini和c:\xampp\sendmail\sendmail.ini为Gmail发送邮件.
在C:\xampp\php\php.ini发现extension=php_openssl.dll并从该行的开头删除分号,使SSL工作Gmail的本地主机.
在php.ini文件中查找[mail function]并更改
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
Run Code Online (Sandbox Code Playgroud)
现在打开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
Run Code Online (Sandbox Code Playgroud)
现在你做到了!! 使用邮件功能创建php文件并从localhost发送邮件.
更新
首先,确保PHP安装具有SSL支持(在输出中查找"openssl"部分phpinfo()).
您可以在PHP.ini中设置以下设置:
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
Run Code Online (Sandbox Code Playgroud)