簡體   English   中英

SMTP錯誤:無法使用PHPMailer連接到SMTP主機

[英]SMTP Error: Could not connect to SMTP host using PHPMailer

我們正在使用SMTP高級身份驗證來使用PHPMailer發送測試郵件。 我們正在將1and1.com服務器與SMTP和SSL一起用於電子郵件交換。 我們需要從第三方服務器運行此php頁面。 我們以下載的PHPMailer軟件包中的示例為例。 我們嘗試使用“ test_pop_before_smtp_advanced”示例和“帶有身份驗證的SMTP高級測試”示例。 在這兩種情況下,我們都會得到相同的錯誤。

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

這是我們編寫的用於發送郵件的php文件。

<html>
<head>
<title>PHPMailer - SMTP advanced test with authentication</title>
</head>
<body>

<?php
echo "hai";
include('class.phpmailer.php');
include('class.smtp.php');
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch


$mail->SMTPSecure = "ssl";
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
echo "hai1";
$mail->IsSMTP(); // telling the class to use SMTP

try {

  $mail->Host       = "smtp.1and1.com"; // SMTP server
  $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->Host       = "smtp.1and1.com"; // sets the SMTP server
  $mail->Port       = 587;                    // set the SMTP port for the GMAIL server
  $mail->Username   = "xxx@abc.com"; // SMTP account username
  $mail->Password   = "xxxxx";        // SMTP account password
  $mail->AddReplyTo('mno@abc.com', 'First Last');
  $mail->AddAddress('mno@abc.com', 'John Doe');
  $mail->SetFrom('xxx@abc.com', 'First Last');
  $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  $mail->Body = 'hello';

 if(!$mail->Send()) {
   echo "Mailer Error: " . $mail->ErrorInfo;
 } else {
   echo "Message sent!";
}
} catch (phpmailerException $e) {
echo "error";
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo "err";
  echo $e->getMessage(); //Boring error messages from anything else!
}
?>

</body>
</html>

任何人都可以在這方面為我們提供幫助,請出於同一目的建議其他簡便方法。 謝謝...

我遇到了同樣的問題,並經歷了許多不同的端口,域和安全性配置嘗試。 嘗試使用這些設置,我在另一個幫助站點上找到了它們,它們為我工作。

$mail->IsSMTP();                                    // Set mailer to use SMTP
$mail->Host = '74.208.5.2';             // Specify main and backup SMTP server (server name)
$mail->Port = 25;                // TCP port to connect to 587 or 465, 425, 25 

$mail->Username = 'xxxxx@xxx.com';  // SMTP username
$mail->Password = 'xxxxxx';        // SMTP password

$mail->SMTPAuth = true;       // Enable SMTP authentication
$mail->SMTPSecure = 'tls';     // Enable TLS encryption, `ssl` also accepted

我必須將SMTPSecutre設置為tls或完全刪除此行,將smtp.1and1.net的ip用於主機(您可以通過ping或whois進行驗證),並將端口設置為25。即使1and1建議使用其他端口的頻率更高。 希望這可以節省一些時間。

PHP在5.6版中突然更改為對SSL連接更加嚴格。 這會導致許多Web聯系人表單中斷,通常不會顯示任何錯誤消息。 如果要繼續使用自簽名證書或允許非SSL(不安全)連接,則可以使用PHPMailer的快速解決方法:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

如果您使用的是SSL連接,請嘗試將端口更改為默認的SSL端口465

如果您不使用SSL,請嘗試刪除以下幾行:

$mail->SMTPSecure = "ssl";
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";

並將端口更改為默認端口25。

由於您無法連接,請花點時間檢查您的登錄詳細信息是否正確,即使是我們中最好的人也可能會誤輸入密碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM