Jump to content

Archived

This topic is now archived and is closed to further replies.

kee2ka4

PHP mail() Function I have got one question

Recommended Posts

Hi! I am using a mail() function in one of my php code. However I have getting the following error:

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:\wamp\www\Car_Project\Registration\Testingtutorial\register.php on line 121

I am using Localhost, Could anyone please tell me what I have done wrong or what setting I am required to change...

Thanks for any Help

Regards,
Keetan

Share this post


Link to post
Share on other sites
Thanks for your reply, I have looked into the mail() function in php.ini and this is what there is:

[mail function]
; For Win32 only.
SMTP = localhost

; 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_paramaters =

Could you tell me what I need to change in that?

Also I have found three files with php.ini extension these are php.ini-recommended (c:\wamp\php), php.ini (c:\wamp\apache2\bin), and php.ini-dist (c:\wamp\php) do I have to change the settings in all of them?

Thanks for your Help...
Regards,
Kee2ka4

Share this post


Link to post
Share on other sites
You need to setup PHP to a an SMTP server. Youm might be able to use your ISPs maiul server if they have an smtp server, so thing like smtp.ispname.com

The defualt SMTP port is fine, as most SMTP servers run on port 25.

NOTE: If your isp requires you to be logged into to send an email to the smtp server, you wont be able to use the mail function. As the mail function doesnt support any authentication protocols.

Share this post


Link to post
Share on other sites
Thanks for your reply. I just wanted to say that I am not using an ISP, I am using a localhost at the moment, and still the mail() is not working. Any suggestion?

Share this post


Link to post
Share on other sites
Do you have an SMTP server installed locally? You need to install an SMTP server locally in order to send emails via localhost.

Share this post


Link to post
Share on other sites
Hi! Thanks for all the Responses! Could anyone point me to the Direction as to how to Install an SMTP server locally? I don't even know if I have an SMTP server. Sorry I am quite new to all this.  ::)

Btw my ISP is pipex and I am using my local host to view my php files and I am using Apache! I just want this mail() to work for me to proceed!

Thanks..

Share this post


Link to post
Share on other sites
I have changed the smtp from localhost to my isp smtp address, however I still get the same error message. The settings I am changed in php.ini is:

[mail function]
; For Win32 only.
SMTP = smtp.dsl.pipex.com
smtp_port = 25

After changing the smtp from localhost to smtp.dsl.pipex.com I still get the same error message. The error message I get is

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:\wamp\www\Car_Project\Registration\Testingtutorial\register.php on line 121

I have gone through many tutorials and researched google pages but didn't get anywhere... Some say to install an smtp server, I even tried that and its just not working

Could anyone help me please? I really can't proceed without sorting this error out... Please give me some light to my problem...

Regards,
Kee2ka4....

Share this post


Link to post
Share on other sites
It appears you havent restarted Apache. You need to restart Apache or what ever your server program is in order for the new php settings to come available.

Share this post


Link to post
Share on other sites
Hi! Thanks for your reply wildteen.... You were right I didn't restart my server but now the error message has changed... now it says the following...

Warning: mail() [function.mail]: SMTP server response: 501 Bad address syntax in C:\wamp\www\Car_Project\Registration\Testingtutorial\register.php on line 121


The mail() function code on line 121 is:

[quote] mail($email_address, $subject, $message, "From: MyDomain Webmaster<me@example.com>\nX-Mailer: PHP/" . phpversion());
echo 'Your membership information has been mailed to your email address! Please check it and follow the directions!';
[/quote]

Any idea's what might be wrong?

Cheeerss

Share this post


Link to post
Share on other sites
Looks like your $email_address variable is holding an invalid email address. Everythink else looks ok

Share this post


Link to post
Share on other sites
The $email_address seems to be fine cause it does successfully add the details to the database! The $email_address is the address that I enter in a form, its just a normal hotmail email account that I enter. I have even tried @yahoo.com @gmail.com and non of them work...?

Any other cluess... if nothing works then I will have to upload it on a webhosting company, but i would really prefer to work on my localhost.... ::)

Share this post


Link to post
Share on other sites
Yes  ;D! I have sorted out the Problem! It took me one whole day lololol ! What I did is I stopped using mail () function and instead replaced it with PHPMailer, this is a php class for sending out emails. Anyone that is having problems with mail(), go throught this tutorial, its is really helpfull...

http://www.phpfreaks.com/tutorials/130/0.php

Understand the PHPMailer class and then apply it into your code! If you want your webform to send emails, and do many other things, use phpmailer, it will work perfectly. The only thing u need to change is the smtp address in the php.ini file. My ISP is pipex and therefore my SMTP = smtp.dsl.pipex.com. Thats it!

Anyways.. I am off, thanks for all the help today!

Regards, Kee2ka4

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.