Jump to content


Photo

Set up to test sending emails from PHP on local PC


  • Please log in to reply
13 replies to this topic

#1 griffon

griffon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 July 2006 - 03:15 PM

Hi - I'm a newbie to PHP programing (about 3 days) so please forgive me if this is a really silly question.

I want to write a php page to send reply e-mails to people contacting my website.

I want to fully test any code on my local pc before uploading it to my website's server.

So far I've succesfully downloaded, installed and configured PHP and Apache on my Windows xp machine.

I've also written little test pages in php and they seem to work.  So far so good.

However, when I try to test a simple php page designed to simply send an email to myself it fails with the following error.

Warning: mail() [function.mail]: Failed to connect to mailserver at "smtp.myisp.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Program Files\Apache Group\Apache2\htdocs\PHP tests\send.php on line 3

*please note myisp and e-mails changed below

From the error message, and reading around on the internet, it looks like the php can't get into my own ISP.  I've tried modifying the php.ini file which initially looked like this:

[mail function]
; For Win32 only.
SMTP = localhost ; for Win32 only
smtp_port = 25
sendmail_from= me@localhost.com ; for Win32 only   

to:

[mail function]
; For Win32 only.
SMTP = smtp.myisp.com ; for Win32 only
smtp_port = 25
sendmail_from = myemaill@myisp.com ; for Win32 only

OK - I can't see how this can access my isp to send the e-mail because there appears to be no way to include my isp password. 

Just in case you ask - firewall configured to give apache access and, yes, apache was set to running.

I'd be very grateful for any advice.

Thanks
:-)

#2 unkownname

unkownname
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 30 July 2006 - 03:37 PM

username:password@smtp.myisp.com

#3 griffon

griffon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 July 2006 - 03:54 PM

OK.

Presumamby I insert this after the SMTP line below do I?

[mail function]
; For Win32 only.
SMTP = smtp.myisp.com ; for Win32 only
smtp_port = 25
sendmail_from = myemaill@myisp.com ; for Win32 onl

#4 unkownname

unkownname
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 30 July 2006 - 04:04 PM

no stmp line is username:password@smtp.myisp.com just as you see it.


#5 griffon

griffon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 July 2006 - 04:20 PM

Doesn't work I'm afraid.  Same error.  I believe the smtp I'm using is right.  Could be the port number, I suppose.  25 seems right but how can I check what it wants I wonder? 

#6 unkownname

unkownname
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 30 July 2006 - 04:24 PM

hmm well theirs this php class on the net i forgot the name i think PHPSend look it up on google. Ill try looking for it sorry about that.


#7 griffon

griffon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 July 2006 - 04:41 PM

thanks for helping.  I have looked around the net and loads of people have had this or similar problems but no one seems to post the solution.  Either they can't be bothered once they find it or they die solving it.  LOL

#8 wildteen88

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

Posted 30 July 2006 - 06:10 PM

mail doesnt support any authentication in order to login to sign in to an SMTP server to send an email, so doing username:password@smtp.myisp.com will not work or any other method. The SMTP address can only be smtp.hostname.com or IP based.

In order for mail to work the SMTP server will need to be open to the public, as in no username/password set in order to send an email.

#9 griffon

griffon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 July 2006 - 08:32 PM

OK.  Thanks.  That certainly seems to explain why this question often posed in help forums never seems to find an answer.  There's some talk of people putting an e-mail server up on their PC to get around this problem.  Which sounds a bit of a hassle.  I guess I'll just have to upload the php to my web server and try it out there. Pity.  I'd like to be able to test everything locally.

#10 griffon

griffon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 July 2006 - 09:04 PM

"I guess I'll just have to upload the php to my web server and try it out there."

So, I did just that and my code works.  Just like that!

Thanks to all who had a go at helping me out.



#11 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 30 July 2006 - 09:36 PM

It sounds to me like you are using xampp or mecury mail if so try this
$knownsender must me a vaild username on the server. Like you@yourdomain.com

if ($ccaddress=="" || $ccaddress==" "){
    $header="From: $knownsender";
	
}else{
     $header .="From: $knownsender\r\n";
     $header .=" Cc: $ccaddress";
}
// $header.="Bcc: $bcaddress";

if (@mail($mailtos, $subject, $message, $header)) {
     echo "Your mail has been sent";
}else{
     echo "There was an error sending your Email";
}

I used to use xampp and it took for ever for me to get it right,not sure if this is correct but it works. Now for this to work You will need to change the php.ini back to the default.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#12 griffon

griffon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 02 August 2006 - 08:20 AM

No.  I'm with ntl actually.  But thanks for your post.  I think now I've had some success with uploading code onto my web site's server, I can test development code there rather than doing it on my local PC.  I guess that's what most of you must do anyway.  :)

#13 wildteen88

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

Posted 02 August 2006 - 10:42 AM

griffon if you are with ntl, which I am you can use this in your php.ini:
SMTP = smtp.ntlworld.com
smtp_port = 25

; For Win32 only.
sendmail_from = ntlUsername@ntlworld.com
In the php.ini, make sure you change ntlUsername@ntlworld.com to your ntl email addy. And that you are using the computer connected to the ntl internet connection.

#14 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 02 August 2006 - 11:19 AM

I have been testing my own email locally foir quite some time.
Are you sure that the smtp.myip.com is a real SMTP server? You must use a real mail server  and a real address.

My normal email provider is planet.nl and their mailserver is mail.planet.nl, so I specified SMTP = mail.planet.nl
My sendmail_from is defined as sendmail_from = myname@planet.nl

Ronald  ;D

RTFM is an almost extinct art form, it should be subsidized.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users