problem with smtp server and mail() function

March 9, 2011 at 17:08:31
Specs: Windows 7
i am working at localhost using WAMP server that includes apache as http server
but when using the email function, i got this message:

Warning: 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\03\send mail.php on line 4

so how can i know if the smtp mail server is installed on my computer, and what is the right smtp_port to use?

See More: problem with smtp server and mail() function

Report •

March 9, 2011 at 20:13:19

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

Window's doesn't come with an MTA, you need to specify an SMTP server.

Report •

March 9, 2011 at 21:52:51
thank you very much for your reply,
first,i am using Windows 7 and i have the "Outlook" program installed, i configured it to use my email(for example as the sender, then i go to control panel>>mail>>
then i checked the port of SMTP that is corresponding with my email(, and i put this number in php.ini>>smtp_port
but it didn't work, although sending via "outlook" program works well.
so is the "Outlook" program is the mail smtp server?
and why didn't that port work(i.e. can you use that port to support more than one email or every email must have a unique port, eventhough this will reject the principle of client-server,)

Report •

March 10, 2011 at 00:44:28
smtp_port should be 25. It's the SMTP=localhost that's the problem - you don't have an SMTP server running at localhost.

Need to set SMTP= to an external SMTP server in php.ini, like:

Note that, some SMTP servers (including gmail's) require you to login to the SMTP server - which native PHP does not support. You'd need to use a package like Mail ( ) to send emails through gmail.

Report •

Related Solutions

March 10, 2011 at 03:24:35
i downloaded "Mail-1.2.0.tgz" but it seems that i need additional files, because when i open "Mail.php" in my browser then:

Warning: require_once(PEAR.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\Mail-1.2.0\Mail.php on line 46

so how can i get the files, and what is the page should i start with

Report •

March 10, 2011 at 03:30:47
could you please explain more deeply from the start to the end, because it seems that i will face a lot of troubles in each stage.
and if there is another solution ,like installing email server, so no problem.
i just wanna my email message to be sent whatever the way

Report •

March 10, 2011 at 12:49:59
Hmm, a linux server would be easier, but w/ Windows you'd need Exchange server or something similar.

You should install PEAR, then pear will do the mail install.

Follow the 'Windows' instructions here:

(Bascially just download the go-pear.phar file & run it: php go-pear.phar )

After pear is installed, you can install Mail with just one command:

pear install Mail

(Again, all this works much better on linux. Maybe you could run the server in a linux virtual machine?)

I don't know of any easy SMTP servers for windows, and even once you setup the MTA, you need to configure the MX on your domain & setup SPF - it can be a real chore. The PEAR_Mail package or using a Linux VM is probbably the easiest solution.

Report •

March 11, 2011 at 00:29:45
i downloaded the go-pear.phar file & i ran it: php go-pear.phar
then i ran: pear install Mail
and all things work well.
when i used php to send an email like that :

$headers="From:\r\n Cc:\r\n";
$success=mail("","trying subjct","hello mosab");

it still give me the same error:

Warning: 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\03\send mail.php on line 4
message has not been sent.

taking into account that the php.ini(that exist in:C:\wamp\bin\php\php5.3.0) still the same after running the previous command(that mentioned first):

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
sendmail_from =

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

so what should i do now:
should i change php.ini
or should i use functions related to "pear" to send an email or just the same function "mail()"

Report •

March 11, 2011 at 01:45:52
Don't use the built in mail() method, use the Mail package.

Also to use gmail you'd need SSL, see the example here -

Need to update host, username, and password. For google, host should be: and username/password is your gmail login.

Report •

March 11, 2011 at 05:21:24
i downloaded all packages required:
Auth_SASL 1.0.2
Mail 1.1.14
Net_SMTP 1.3.2
Net_Socket 1.0.9

and i used the right php code as in:

and i used various ports like:25,587,465 and tls,ssl but no combination of them works well, i get the error:

Failed to connect to ssl:// [SMTP: Failed to connect socket: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (code: -1, response: )]

so what is the reson(is there a congiguration in php should i set)

Report •

Ask Question