簡體   English   中英

PHPMailer無法正常工作?

[英]PHPMailer not working?

我的PHPMailer腳本不適用於此處的表單。 我正在使用Gmail SMTP。 該表格沒有附件選項,所以我禁用了它。 請注意,我已將SMTP登錄信息(從電子郵件和電子郵件替換為虛擬電子郵件)僅用於在stackoverflow上發布。 順便說一句,它與autoload.php文件的絕對URL有關系嗎?

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require content_url('/phpmailer/vendor/autoload.php');

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 1;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'example@gmail.com';                 // SMTP username
    $mail->Password = 'secret';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('example2@gmail.com', 'example2');
    $mail->addAddress('example3@gmail.com');     // Add a recipient

    //Attachments
    // $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Application form submission';
    $mail->Body    = $message;
    $mail->AltBody = strip_tags($message);

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

誰能告訴我為什么它不起作用?

我收到以下錯誤:

注意:未定義的索引:/nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65)中的income_checkbox:第495行的eval()代碼

警告:require():在服務器配置中,通過/nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php中的allow_url_include = 0禁用https://包裝器(65):第5164行的eval()代碼

警告:require( https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php ):無法打開流:在/ nas / content / live / financemi /中找不到合適的包裝器wp-content / plugins / insert-php-code-snippet / shortcode-handler.php(65):eval()在第5164行上的代碼

致命錯誤:require():無法打開所需的內容' https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php'(include_path ='。:/ usr / share / pear / php: /nas/content/live/financemi/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65)中的/ usr / share / php:/ usr / share / pear'):eval( )第5164行的代碼

您需要在本地而不是通過HTTP / HTTPS require自動加載器。 (因為通過HTTP,您將requiring腳本的輸出,該輸出為空,而不是其代碼。)

更改:

require 'https://www.financemi.com.au/wp-content/phpmailer/vendor/autoload.php';

至:

require __DIR__.'/../../../wp-content/phpmailer/vendor/autoload.php';

(更新以反映PHP腳本在wp-content / plugins / insert-php-code-snippet /目錄中獲得了eval()。)

暫無
暫無

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

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