我通過functions.php 設置了一個wordpress 站點,以將SMTP 與PHPMailer 結合使用(下面的代碼片段)。add_action( 'phpmailer_init', 'setup_phpmailer_init' );function setup_phpmailer_init( PHPMailer $phpmailer ) { $phpmailer->Host = 'HOSTNAME'; // for example, smtp.mailtrap.io $phpmailer->Port = 587; // set the appropriate port: 465, 2525, etc. $phpmailer->Username = 'YOURUSERNAME'; // your SMTP username $phpmailer->Password = 'YOURPASSWORD'; // your SMTP password $phpmailer->SMTPAuth = true; $phpmailer->SMTPSecure = 'tls'; // preferable but optional $phpmailer->IsSMTP();除了 WooCommerce 之外,這對所有內容都沒有問題。WooCommerce 無法發送電子郵件,并出現以下錯誤:2020-08-18T00:36:33+00:00 CRITICAL Uncaught TypeError: Argument 1 passed to setup_phpmailer_init() must be an instance of PHPMailer, instance of PHPMailer\PHPMailer\PHPMailer given, called in PathToWordpress/web/wp/wp-includes/class-wp-hook.php on line 287 and defined in PathToWordpress/web/app/themes/theme-name/functions.php:362Stack trace:#0 PathToWordpress/web/wp/wp-includes/class-wp-hook.php(287): setup_phpmailer_init()#1 PathToWordpress/web/wp/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters()#2 PathToWordpress/web/wp/wp-includes/plugin.php(544): WP_Hook->do_action()#3 PathToWordpress/web/wp/wp-includes/pluggable.php(494): do_action_ref_array()#4 PathToWordpress/web/app/plugins/woocommerce/includes/class-wc-emails.php(650): wp_mail()#5 PathToWordpress/web/wp/wp-includes/class-wp-hook.php(287): WC_Emails->no_stock()#6 PathToWordpress/web/wp/wp-includes/class-wp-hook.php(311): WP_Hook->apply in PathToWordpress/web/app/themes/theme-name/functions.php on line 362可能是什么原因導致此錯誤?
1 回答

開心每一天1111
TA貢獻1836條經驗 獲得超13個贊
轉動這條線:
函數 setup_phpmailer_init( PHPMailer $phpmailer) {
進入此(刪除 PHPMailer)修復了錯誤
函數 setup_phpmailer_init($phpmailer) {
我不完全確定為什么
- 1 回答
- 0 關注
- 109 瀏覽
添加回答
舉報
0/150
提交
取消