2010-08-20 66 views
2

我正面臨着一個奇怪的問題.. iv在使用谷歌smtp,雅虎smtp和aol smtp在PHP發送郵件寫了一些代碼。它的工作正常。但當我試圖在不同的服務器和域上運行相同的代碼它給我以下錯誤:相同的程序沒有運行在不同的服務器上

SMTP錯誤:無法連接到SMTP主機。

任何解決方案??

+0

該服務器可以通過命令行(ping,ftp,telnet等)查看SMTP主機嗎? – ChrisF 2010-08-20 11:58:37

+0

我該如何檢查? – chill 2010-08-20 11:59:10

+0

其他資訊?網絡連接和DNS名稱解析工作?什麼是PHP版本,服務器軟件和版本,PHP配置細節等等...現在的水晶球相當昂貴... – 2010-08-20 11:59:55

回答

1

很可能您不允許連接到端口25.請與託管公司檢查用於發送郵件的SMTP服務器。

+0

即時通訊不使用端口25 – chill 2010-08-20 12:10:06

+0

它們可能阻止了任何傳出端口。標準做法是隻允許來自虛擬主機環境的受控流量。 – 2010-08-20 15:43:10

0
<?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++; 
    } 
?> 
+0

你應該編輯你的問題,而不是發佈一個答案 – ChrisF 2010-08-20 12:10:54

+0

亞真!但最好給我一個解決方案.. – chill 2010-08-20 12:11:41

相關問題