duanbairan4235
2013-05-06 11:11
浏览 61
已采纳

从php代码发送电子邮件

I want to send an e-mail using a php code,I am using wampserver.

an error appear :

 mail() [function.mail]: 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\Newsletter1\index.php on line 29

My file php.ini

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = myEmail@gmail.com

Is there any more configuration to do?

Update

I'am using the mail function to send a newsletter to subscriber and I am testing now locally then I will test the code on production environment

图片转代码服务由CSDN问答提供 功能建议

我想使用php代码发送电子邮件,我正在使用wampserver。

出现错误:

  mail()[function.mail]:无法连接到“localhost”端口25的邮件服务器,验证您的“SMTP”和 在php.ini中设置“smtp_port”或在第29行的C:\ wamp \ www \ Newsletter1 \ index.php中使用ini_set()
   
 
 

我的 文件php.ini

  [mail function] 
; 仅适用于Win32。
;  http://php.net/smtp
SMTP = localhost 
;  http://php.net/smtp-port
smtp_port = 25 
 
; 仅适用于Win32。
;  http://php.net/sendmail-from
sendmail_from = myEmail@gmail.com 
   
 
 

还有其他配置要做吗?

更新

我正在使用mail函数向订阅者发送简报,我现在正在本地测试然后我将在生产环境中测试代码 \ n

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • douxiao0400 2013-05-06 11:13
    已采纳

    You need a SMTP mailserver daemon running on localhost. If you are using a unix host and you don't want to setup a full SMTP agent, try removing the SMTP config part, thus directly using sendmail. From the docs:

    The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

    打赏 评论
  • doukou1718 2013-05-06 11:16

    If you are working on a test environement look at this link: http://www.toolheap.com/test-mail-server-tool/

    This little app will simulate an SMTP server on your computer.

    It gives you some hint on how to test and debug mail features for your php applications.

    打赏 评论
  • doson1998 2013-05-06 11:17

    Check your Firewall maybe php is blocked to connect server. Or try change localhost to 127.0.0.1 .

    打赏 评论
  • douchen1988 2013-05-06 11:19

    You need either smtp server on your server or you need to connect to external smtp server to send email.

    to connect via external smtp you can use

    http://pear.php.net/package/Mail

    here is answer to your question as well with an example of how to use it.

    smtp configuration for php mail

    打赏 评论

相关推荐 更多相似问题