【问题标题】:Warning: trim() expects parameter 1 to be string, array given in wp-includes/class-phpmailer.php on line 973警告:trim() 期望参数 1 是字符串,数组在 wp-includes/class-phpmailer.php 第 973 行给出
【发布时间】:2015-04-29 23:47:15
【问题描述】:

我正在尝试使用函数 wp_mail 从我的 wordpress 网站发送一封电子邮件,但我收到了这个错误:

Warning: trim() expects parameter 1 to be string, array given in /var/www/html/wp-includes/class-phpmailer.php on line 973 0

我真的不明白我为什么会得到它。

这是我当前的代码:

// Contact form  Ajax 

add_action('wp_ajax_nopriv_submit_contact_form', 'submit_contact_form'); 

function submit_contact_form(){

    if(isset($_POST['email'])) {

        $email = $_POST['email'];       
        $email_to = "info@yyy.com";

        $host = "ssl://smtp.gmail.com:465";
        $username = 'myEmail@gmail.uk';
        $password = 'mypassword';

        $email_subject = "You have a new email from $email via yyy.com website";
        $message = $_POST['text']; 

        $headers = array ('From' => $email, 'To' => $email_to,'Subject' => $email_subject);
        /*$smtp = Mail::factory('smtp',
          array ('host' => $host,
            'auth' => true,
            'username' => $username,
            'password' => $password));*/

        //$mail = $smtp->send($email_to, $headers, $message);

        wp_mail( $email_to, $headers, $message );

        /*if (PEAR::isError($mail)) {
          echo($mail->getMessage());
        } else {
          echo("Message successfully sent!\n");
        }*/
    }
}



error_reporting(E_ALL);
ini_set("display_errors", 1);

【问题讨论】:

  • 这段代码中没有修剪调用!你的错误在这里class-phpmailer.php on line 973
  • 我不是一个铁杆 wordpress 专业人士,但我猜它正在 html/wp-includes/class-phpmailer.php 中使用 wp_mail() 函数正在使用的第 973 行。跨度>
  • 我认为您的参数顺序错误,请参阅:codex.wordpress.org/Function_Reference/wp_mail (<?php wp_mail( $to, $subject, $message, $headers, $attachments ); ?> )
  • 我将“主题”参数称为“标题”。我不认为这是原因
  • 这是您的错误! $headers 必须是字符串!

标签: php wordpress


【解决方案1】:

我安装了一个名为“PostFix”的包,它负责从 Ubuntu 服务器(我使用的服务器 linux)发送电子邮件,它解决了问题!

【讨论】:

    猜你喜欢
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 2021-12-28
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多