0

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

4 Answers4

1

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).

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
  • should I download a mailserver? – Michelle Dali May 06 '13 at 11:16
  • Are you running Windows on the server? If so, the simplest way is using IIS SMTP server, refer to this [Microsoft TechNet article](https://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e4cf06f5-9a36-474b-ba78-3f287a2b88f2.mspx?mfr=true). If running Linux/BSD you can use either Postfix (which a real SMTP agent) or directly sending from `mail()` (no SMTP required) thanks to sendmail facility. If you want to send a large volume of e-mail messages (mailing lists, **hopefully no spam**), then you definitely need a SMTP agent. – Stefano Sanfilippo May 06 '13 at 11:20
0

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.

sebataz
  • 1,025
  • 2
  • 11
  • 35
0

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

0

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

Community
  • 1
  • 1
Robert
  • 19,800
  • 5
  • 55
  • 85