Go Premium for a chance to win a PS4. Enter to Win


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 http://phpmailer.sourceforge.net/ 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().
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

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 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 smtp.myhost.com. 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses

927 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