简体   繁体   中英

How to send an email from PHP

I'm trying to send an email from my PHP script but it doesn't work. This is the error I get:

Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and 
"smtp_port" setting in php.ini or use ini_set()

So I've tried to change the port and smtp port by using iniset() function, may i don't know is it possible or not.

如果您使用的是Linux,则必须安装一个邮件服务器,例如postfix,执行此命令apt-get install postfix ,然后启动服务器,然后可以使用php mail()函数发送电子邮件!

You'll need to setup a mail server on your localhost. Or, you could connect to an external mail server. Hell, even Gmail allows you to connect via SMTP (cool for testing email scripts etc).

So I've tried to change the port and smtp port by using iniset() function, may i don't know is it possible or not.

It is. See the manual for mail configuration . Both those entries are marked as PHP_INI_ALL

You can prove this by using iniset and then trying your mail call again. The error message will either go away or change (eg to complain that it can't connect to whatever server you've said to use instead of localhost:25).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM