簡體   English   中英

PHPMailer 不適用於虛擬主機

[英]PHPMailer not working on Web Hosting

我已經能夠使用 xampp 發送電子郵件,但是當我嘗試在我的在線服務器中使用它時,它似乎不起作用。 我嘗試更改寫在我的電子郵件帳戶信息上的值。 這似乎不起作用,我希望為遇到此問題的任何人提供任何指導或幫助。

這是電子郵件帳戶的詳細信息

電子郵件帳戶詳細信息

那么這是我的mailer.php代碼

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {

  $mail->SMTPDebug = 2;

  $mail->isSMTP();
  $mail->Host = 'localhost';
  $mail->Username = 'email';
  $mail->Password = 'password';

  $mail->SMTPSecure = 'ssl';
  $mail->SMTPAuth = true;
  $mail->Port = 465;

  $mail->setFrom('email', 'Test Message');

  $mail->addAddress("email");

  $mail->isHTML(true);
  $mail->Subject = 'This is the Subject';
  $mail->Body    = 'This has been sent';
  $mail->AltBody = 'This has been sent';

  $mail->send();
  echo 'Message has been sent';

 } catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: <br>', $mail->ErrorInfo;
 }

我收到錯誤SMTP 錯誤:無法連接到服務器:連接被拒絕 (111) SMTP 連接()失敗。

我對這個還是有點陌生​​,所以提前抱歉。 我覺得我離讓它工作很近了哈哈!

在此先感謝您的幫助! :D

太簡單了...使用以下代碼:

<?php
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;

    require 'PHPMailer/src/Exception.php';
    require 'PHPMailer/src/PHPMailer.php';
    require 'PHPMailer/src/SMTP.php';
    $mail = new PHPMailer(true);
    $name = 'Name to be displayed!';
    $message = 'Never Give Up!';
    $subject = 'Test mail!';
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 587;
    $mail->SMTPAuth = true;
    $mail->Username = 'yourmail@gmail.com';
    $mail->Password = 'youpass';
    $mail->SMTPSecure = 'tls';
    $mail->addReplyTo($to, $name);
    $mail->setFrom($to, $name);
    $mail->addAddress($to);
    $mail->Subject = $subject;
    $mail->msgHtml($message);
    $mail->send();
?>

希望您在根目錄中添加了 PHPMailer 庫,如果沒有,請檢查路徑

暫無
暫無

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

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