Link to home
Start Free TrialLog in
Avatar of fanar
fanar

asked on

PHP mail problems

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";
mail($to,$subject,$message);
Avatar of RWJDCom
RWJDCom
Flag of United States of America image

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.

-Jeff
Avatar of Robin Hickmott
Robin Hickmott

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.
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().
Yes, asecnt, but if your SMTP server requires authentaction you can't set that information in the php.ini.  Thats why I recommended phpmailer.

-Jeff
PEAR::Mail's docs indicate that it supports authentication.
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.
Avatar of fanar

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Robin Hickmott
Robin Hickmott

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial