PHP mail problems

Posted on 2006-11-23
Last Modified: 2008-02-01
I am developing a website and I have it setup so whenever you register for a new account it sends an email for activation. However when I try to use the mail function I get an error.
I am currently running wamp.

This is the error i get:
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:\home\home_install\wamp\www\Books\register.php on line 64

my php.ini section for the mail function.

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

my php code:

$to = $regemail;
$subjust = "activation";
$message = "test message";
Question by:fanar

Expert Comment

ID: 18004922
The mail system seems like it is trying to connect to a SMTP server on your local machine and it is unable to.  My suggestion would be to use phpmailer which you can find at and with that PHP class you are able to set the SMTP server, login, and password.  You will need to have a mail account somewhere with SMTP access and just use that account to send the email out.

Check the documentation of phpmailer on how to do this and if you are still having problems please let me know and I will let you know the exact syntax of what I use.

I hope this helps.

LVL 13

Expert Comment

ID: 18005481
change localhost to the address of your ISPs Outgoing Mail Server or yours if you have one.

PHP has no mail system built in it just calls a standard mail server.

Expert Comment

ID: 18005697
RWJDCom, you can also set the SMTP server with just vanilla PHP, in php.ini (like the settings the asker quoted) or with ini_set().
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why


Expert Comment

ID: 18005749
Yes, asecnt, but if your SMTP server requires authentaction you can't set that information in the php.ini.  Thats why I recommended phpmailer.


Expert Comment

ID: 18006782
PEAR::Mail's docs indicate that it supports authentication.
LVL 13

Expert Comment

ID: 18006794
Yes but there is a chance the users server WONT have SMTP authentication if he doesent know what it is then the chances are hes using his ISPs which is liklely to be Open Relay anyway.

Why bother going into setting up PHPMailer when the issue can be resolved quite simply by adding a line to the php.ini. If the user then requires authentication they can look at adapting their code.

Author Comment

ID: 18008784
how do i find what my ISPs is?
Another question then: once i am done developing it I am moving the website to an actual webhost, do most of them support mail with php?
LVL 13

Accepted Solution

rhickmott earned 200 total points
ID: 18008805
Yes most web hosts have a outgoing mail server as they are in control of the php set-up and installation you wont have to worry about this you should find the mail() command will just work

Who is your Internet Service Provider? if you look at the mail settings for them they will provide you with an outgoing mail server normally something like Get this address and place it as the server address in the php.ini and your mail commands should then work.

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question