Improve company productivity with a Business Account.Sign Up


PHP mail problems

Posted on 2006-11-23
Medium Priority
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

by:Robin Hickmott
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().
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.


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

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

Expert Comment

by:Robin Hickmott
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

Robin Hickmott earned 800 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

606 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