我必须向 gamil 发送电子邮件以在我的网站上注册帐户。我正在使用 wamp,win 7,codeigniter。并通过sendmail发送邮件。我已经进行了所有必需的更改,即
在 php.ini 中
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 465
; For Win32 only.
;sendmail_from = <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="75180c1018141c19351218141c195b161a18" rel="noreferrer noopener nofollow">[email protected]</a>
sendmail_path ="C:\wamp\sendmail\sendmail.exe -t"
在sendmail.ini中
smtp_server=smtp.gmail.com
smtp_port=465
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e48591908cbb919781968a858981d9899d8189858d88a48389858d88ca878b89" rel="noreferrer noopener nofollow">[email protected]</a>
auth_password=mypassword
但它显示此错误而不是发送电子邮件。
消息:mail():无法连接到“localhost”端口 25 上的邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或使用 ini_set() 文件名:libraries/Email.php
端口 25 上仍然出现错误,但我正在使用端口 465。这可能是什么原因?我做错了什么? 任何帮助。
最佳答案
我认为您必须重新启动服务器。
编辑 我发现this thread解决方案:
Add the following code to the top of your email script if your mail script continues to fail.
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.YourDomain.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0355626f6a67466e626a6f4260606c766d77435a6c7671476c6e626a6d2d606c6e" rel="noreferrer noopener nofollow">[email protected]</a>');
关于php - 在php codeigniter中发送电子邮件到gmail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16497228/