Simple PHP mailer - Failed to connect to mailserver

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sokka888
Forum Newbie
Posts: 11
Joined: Sun Jan 18, 2009 7:44 pm

Simple PHP mailer - Failed to connect to mailserver

Post by sokka888 »

Hi ppl,

I'm using simple PHP mailer and it fails to connect to mail server.

This is the code:

Code: Select all

 
        $toEmail = "ramwy@myemail.com";
 
        $subject = "Your access details for Learning Managment System (LMS)";
        $message = "Dear Colleague,<br><br>";
        $toEmail = "ramwy@myemail.com";
        $fromemailid="ramwy@myemail.com";
        $fromemail = "ramwy Email <".$fromemailid.">"; //\r\n optional headerfields 
    
        $headers = "From: $fromemailid\n";
        mail($toEmail,$subject,$message,$headers);  // LINE 48 the error line
 
 
This is the error I'm getting with I run the code:

Code: Select all

 
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:\_webserver\emailer\test_emailer.php on line 48
 
 

What should I change on ini_set() to make the email working? pls help :banghead:

Thanks
Sokka
nga
Forum Commoner
Posts: 46
Joined: Mon Aug 17, 2009 3:05 am

Re: Simple PHP mailer - Failed to connect to mailserver

Post by nga »

hi, not so sure what that message means but some servers dont support SMTP (for sending of form from your website to your account)

Or the mail service on the server is wrongly configured
sokka888
Forum Newbie
Posts: 11
Joined: Sun Jan 18, 2009 7:44 pm

Re: Simple PHP mailer - Failed to connect to mailserver

Post by sokka888 »

I'm on WAMP

My php.ini is as below:

Code: Select all

 
 
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
 
; For Win32 only.
;sendmail_from = me@example.com
 
; 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 =
 
Its the default php.ini settings, I've not changed it. Is the above config wrong?

any suggestions? to over come this issue and be able to send out emails?

Thanks
sokka888
Forum Newbie
Posts: 11
Joined: Sun Jan 18, 2009 7:44 pm

Re: Simple PHP mailer - Failed to connect to mailserver

Post by sokka888 »

I finally fixed the problem, added in the php page I specified the different SMTP server and the port.

Initially the port was blocked. And I had to open the port to make the Apache talk with mailserver

Code: Select all

 
   ini_set("SMTP","x.x.x.x");
   ini_set("smtp_port","25");
 
:D
Post Reply