Jump to content

Set up to test sending emails from PHP on local PC


griffon

Recommended Posts

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.

[color=red]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[/color]

[color=purple]*please note myisp and e-mails changed below[/color]

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
:-)
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[font=Verdana]"I guess I'll just have to upload the php to my web server and try it out there."[/font][color=red][/color]

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

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

Link to comment
Share on other sites

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

[code=php:0]
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";
}
[/code]

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.
Link to comment
Share on other sites

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.  :)
Link to comment
Share on other sites

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

; For Win32 only.
sendmail_from = ntlUsername@ntlworld.com[/code]
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.
Link to comment
Share on other sites

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 [b]SMTP = mail.planet.nl[/b]
My sendmail_from is defined as [b]sendmail_from = myname@planet.nl[/b]

Ronald  ;D
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.