相同的程序不在不同的服务器上运行

时间:2010-08-20 11:57:18

标签: php

我面临一个奇怪的问题..我在使用google smtp,yahoo smtp和aol smtp发送邮件时写了一些代码。它的工作正常。但是当我试图在不同的服务器和域上运行相同的代码时,它会给我以下错误:

SMTP错误:无法连接到SMTP主机。

任何解决方案??

2 个答案:

答案 0 :(得分:1)

很可能您不允许连接到端口25.请与托管公司联系以查找用于发送邮件的SMTP服务器。

答案 1 :(得分:0)

    <?php
require_once('class.phpmailer.php');
require_once 'Excel/reader.php';
//$myid=$_REQUEST['myid'];
//$mypass=$_REQUEST['mypass'];
//$msg=$_REQUEST['msg'];
define('GUSER', 'ss@ss.com'); // 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, 'ss@ss.com', 'name', 'Subject', 'trying the aol');
        $y++;
     }  
      $x++;
  }
?>
相关问题