3

When calling the mail function it produces the error

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

I am using Wampserver 2 and I assume the error is because Wamp does not come with a mail server. I then added the following code (as per an answer here)

ini_set("SMTP","aspmx.l.google.com");
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: test@gmail.com" . "\r\n";
mail("email@domain.com","test subject","test body",$headers);

and it produced the following error

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

In the php.ini file located in C:\wamp\bin\php\php5.4.3 it contains the following settings

[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 = you@yourdomain

How can I send e-mail while running the files locally?

Where I'm working it really isn't redibly available which information the companies ISP uses for mail (in fact the company is it's own ISP). Is there another way to test this without finding the right port, if one even exists?

Community
  • 1
  • 1
Celeritas
  • 14,489
  • 36
  • 113
  • 194

2 Answers2

3

install smtp4dev and you're done

http://smtp4dev.codeplex.com/

Lasithds
  • 2,161
  • 25
  • 39
0

Check if you are able to use port 25 for email. Some providers won't allow it. For example: http://customer.comcast.com/help-and-support/internet/email-client-programs-with-xfinity-email/. Figure out what is recommended for your set up and change your php.ini. Update if that doesn't work.

To verify: Google some variation of "does [your internet service provider] allow outgoing emails on port 25" or "does [your internet service provider] block emails on port 25" this should give you some feedback from people that have encountered this problem before.

If that doesn't yeild results there are some command line approaches to verifying if port 25 is open: https://kb.mediatemple.net/questions/888/Checking+your+outgoing+mail+server+%28Is+Port+25+blocked%3F%29

If your provider has blocked port 25 it is probable that they have provided an alternative port to use. Track it down and switch your smtp_port in your php.ini file and see if that resolves the problem.

lostphilosopher
  • 4,361
  • 4
  • 28
  • 39
  • Can you elaborate? Is what I'm doing is running a port scan to see which ports I have open? – Celeritas Jul 30 '13 at 19:58
  • You are currently using smtp_port 25 for your outgoing emails. This is the most common port. However, it is possible that your email provider has blocked it. If this is the case then you will need to use the port that they recommend. My internet provider is Comcast Xfinity so I needed to switch to port 465 before I was able to send outgoing emails through localhost. So, first google "does [YOUR ISP] allow outgoing emails on smtp_port 25" that might give you an easy answer. If not, try this: https://kb.mediatemple.net/questions/888/Checking+your+outgoing+mail+server+%28Is+Port+25+blocked%3F%29 – lostphilosopher Jul 30 '13 at 20:31