chill
chill

Reputation: 41

same program not running on a different server

Im facing a strange problem.. iv written some codes on sending mails using google smtp, yahoo smtp, and aol smtp in php. its working fine. but when im trying to run the same codes on a different server and domain it is giving me the following error:

SMTP Error: Could not connect to SMTP host.

any solutions??

Upvotes: 2

Views: 209

Answers (2)

chill
chill

Reputation: 41

    <?php
require_once('class.phpmailer.php');
require_once 'Excel/reader.php';
//$myid=$_REQUEST['myid'];
//$mypass=$_REQUEST['mypass'];
//$msg=$_REQUEST['msg'];
define('GUSER', '[email protected]'); // Gmail username
define('GPWD', 'pass'); // Gmail password
function smtpmailer($to, $from, $from_name, $subject, $body) { 
    global $error;
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = 'smtp.aol.com';
    $mail->Port = 465; 
    //$mail->AddAttachment('upload/logo.png', 'logo.png'); 
    $mail->Username = GUSER;  
    $mail->Password = GPWD;           
    $mail->SetFrom($from, $from_name);
    $mail->IsHTML(true); // send as HTML
    $mail->Subject = "This is the subject";
    //$mail->MsgHTML(file_get_contents('test.html'));

    $mail->Body = $body;
    $mail->AddAddress($to);
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Message sent!';
        return true;
    }
}
    // initialize reader object
    $excel = new Spreadsheet_Excel_Reader();

    // read spreadsheet data
    $excel->read('Book1.xls');      
    // iterate over spreadsheet cells and print as HTML table
    $x=1;
    while($x<=$excel->sheets[0]['numRows']) {
      $y=1;
      while($y<=$excel->sheets[0]['numCols']) {
        $cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : '';


smtpmailer( $cell, '[email protected]', 'name', 'Subject', 'trying the aol');
        $y++;
     }  
      $x++;
  }
?>

Upvotes: 0

Emil Vikstr&#246;m
Emil Vikstr&#246;m

Reputation: 91922

Most probably you are not allowed to connect to port 25. Check with the hosting company which SMTP server to use for outgoing mail.

Upvotes: 1

Related Questions