Jump to content


Photo

PHP mail() Function I have got one question


  • Please log in to reply
12 replies to this topic

#1 kee2ka4

kee2ka4
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 27 August 2006 - 10:59 PM

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

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 August 2006 - 11:13 PM

you need to set the mail in the php.ini
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 kee2ka4

kee2ka4
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 28 August 2006 - 10:56 AM

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

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 August 2006 - 04:09 PM

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.

#5 kee2ka4

kee2ka4
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 28 August 2006 - 11:00 PM

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?



#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 August 2006 - 08:49 AM

Do you have an SMTP server installed locally? You need to install an SMTP server locally in order to send emails via localhost.

#7 kee2ka4

kee2ka4
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 29 August 2006 - 09:46 AM

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..

#8 kee2ka4

kee2ka4
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 29 August 2006 - 12:38 PM

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....

#9 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 August 2006 - 01:06 PM

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.

#10 kee2ka4

kee2ka4
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 29 August 2006 - 01:20 PM

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:

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!';


Any idea's what might be wrong?

Cheeerss

#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 August 2006 - 01:23 PM

Looks like your $email_address variable is holding an invalid email address. Everythink else looks ok

#12 kee2ka4

kee2ka4
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 29 August 2006 - 01:43 PM

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.... ::)

#13 kee2ka4

kee2ka4
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 30 August 2006 - 12:28 AM

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...rials/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users