tags:

views:

805

answers:

3

I am using the following code to send mail to a smtp server .

<?php

// example on using PHPMailer with GMAIL
include("PHPMailer/class.phpmailer.php");
include("PHPMailer/class.smtp.php"); // note, this is optional - gets called from main class if not already loaded

$mail             = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mucse491.eu.xxxxx.com";      // sets GMAIL as the SMTP server
$mail->Port       = 143;                   // set the SMTP port
$mail->Username   = "[email protected]";  // GMAIL username
$mail->Password   = "xxxx";            // GMAIL password

$mail->From       = "[email protected]";
$mail->FromName   = "mithun";
$mail->Subject    = "This is the subject";
$mail->AltBody    = "This is the body when user views in plain text format"; //Text Body
$mail->WordWrap   = 50; // set word wrap

$mail->AddAddress("[email protected]","First Last");

$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message has been sent";
}

?>

When I run it from the command line I get the following error

PHP Deprecated:  Function eregi() is deprecated in C:\wamp\www\phpmailer\class.p
hpmailer.php on line 593

Deprecated: Function eregi() is deprecated in C:\wamp\www\phpmailer\class.phpmai
ler.php on line 593
PHP Warning:  fputs() expects parameter 1 to be resource, integer given in C:\wa
mp\www\phpmailer\class.smtp.php on line 213

Warning: fputs() expects parameter 1 to be resource, integer given in C:\wamp\ww
w\phpmailer\class.smtp.php on line 213
Mailer Error: SMTP Error: Could not connect to SMTP host.

When i run from the browser I get the following error

Deprecated: Function eregi() is deprecated in C:\wamp\www\phpmailer\class.phpmailer.php on line 593

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. in C:\wamp\www\phpmailer\class.smtp.php on line 122

Warning: fsockopen() [function.fsockopen]: unable to connect to mucse491.xx.xxxxx.com:143 (php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. ) in C:\wamp\www\phpmailer\class.smtp.php on line 122
Mailer Error: SMTP Error: Could not connect to SMTP host.

Please someone guide me .

A: 

Apparently the hostname mucse491.eu.infineon.com cannot be resolved. Do you get a correct IP address when you resolve it with nslookup, host, or whatever ?

Zed
Yes when I use nslookup . I get the correct IP.
mithunmo
On the machine where the PHP script is running?
Zed
+1  A: 

Looks like you have a version of PHPMailer designed to work with an older version of PHP.

So:

1) Downgrade to a lower version of PHP that is compatible

or

2) Upgrade your PHPMailer to a newer version (if it exists)

or

3) Use a different mailing library

Zak
Same code works for the gmail smtp server . But not for my company's server
mithunmo
It may be that the code works for a different SMTP server because the code executes differently for different Servers. For example, one server may require SMTP auth and another doesn't. So you may be hitting a section of code that is invalid for a given SMTP communication standard.
Zak
Another great thing about most PHP libraries is they include the source code. Go ahead and copy and paste in lines 580 - 610 or so around the code that is throwing the error in class.phpmailer.php . That will be more helpful, as it looks like fputs is not getting a valid handle
Zak
A: 

Have you tried putting the IP address of the SMTP server directly in $mail->Host? For one reason or another PHP is having trouble resolving the DNS of the server you are trying to use.

Littlejon