Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending mail

Status
Not open for further replies.

Kurt111780

Technical User
Nov 20, 2003
235
GB
Hello, I just installed php, and smtp server on windows. I have a script that sends an email message but I keep getting the error.

Warning: 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 D:\myRoot\myFolder\myFile.php on line 149

Is this a problem with php setup or smtp server? How can I tell and what should I try?

Thanks,
Kurt

It's only easy when you know how.
 
try opening a dos box or terminal (depending on os) and type in
Code:
telnet localhost 25

if your mail server is configured ok you should get the start of an smtp session. if not - there's at least one of the problems.
 
hm not sure if thats working or not. when I type telnet localhost 25, command prompt window just goes blank. If i press a key it goes back to command prompt.

It's only easy when you know how.
 
sounds like a problem with your smtp server. on mine i get a nice message like this:
Code:
220 ********* Microsoft ESMTP MAIL Service, Version: 6.0.2600.2180 ready
 at  Wed, 1 Feb 2006 17:48:41 +0100

if you are running windows have you turned on the smtp service?
 
Ok, I get that now also. Had the wrong ip address selected in the smtp virtual server settings.

Now I'm getting this error.

Warning: mail(): SMTP server response: 501 5.5.4 Invalid Address in D:\myRoot\myFolder\myFile.php on line 149

This script worked fine on another server.

Kurt

It's only easy when you know how.
 
i'd guess you are using the IIS smtp service? if correct i'd also bet that the from address is not formatted in the way that IIS idiosyncratically likes.

for example this does not work
Code:
   $headers .= "From: \"".$name."\" <".$address.">\n";
instead you need to do this
Code:
   $headers .= "From: \"".$fromaddress."\"\n";

the alternative is to apply a fix to IIS6. check out this MS KB article:
if you're not using IIS then we'll look at other issues.
 
Hi, I am using IIS smtp service. This is what I have. If this is the problem, how can I make it work?
Code:
//set Variables
	$to		= $toName . " <" . $toEmail . ">";
	$from	= $fromName . " <" . $fromEmail . ">";
	$subject	='My Subject';
	$body = "My body";

  ini_set("SMTP","localhost");
  ini_set("smtp_port","25");
  ini_set("sendmail_from",$fromEmail);

  $headers = "Bcc:" . $from . "\r\n";
	
  //specify MIME version 1.0
  $headers .= "Content-Type: text/html; charset=iso-8859-1\n";

  if(mail ($to, $subject, $body, $headers ))
  {
      echo "<b>Your email was sent!</b><br />";
}


It's only easy when you know how.
 
exactly like i said in my earlier post!


either change
the line
Code:
 $from    = $fromName . " <" . $fromEmail . ">";
to
Code:
 $from    = $fromEmail;

or apply the fix in the MSKB article i pointed you towards!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top