wordpress:发送电子邮件时将保存字段发送到数据库-错误500

问题描述 投票:0回答:1

我正在尝试将提交表单的内容保存到数据库表中。但是,当我提交表单时,我收到错误500,但未显示任何调试错误。如果我删除了向表中插入数据的行,则该表单将被发送而没有任何错误。

这里是代码:

function send_mail($fields)
{
    $subject = "New Quotation Form";
    $to = ["[email protected]"];

    extract($fields);
    ob_start();
    require 'email-template.php';
    $message = ob_get_contents();

    ob_end_clean();

    //insert quotation form contents to database table submitted_forms
    global $wbpd;
    $table = "submitted_forms";
    $data = array(
            'content' => $message,
            'datetime' => date("Y-m-d H:i:s"),
            'from_email' => $email
        );

    $ok = $wpdb->insert($table, $data); //it breaks here, if I remove it form is sent successfully

    if($wpdb->last_error !== '') :

        $str   = htmlspecialchars( $wpdb->last_error, ENT_QUOTES );
        $query = htmlspecialchars( $wpdb->last_query, ENT_QUOTES );

        print "<div id='error'>
        <p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br />
        <code>$query</code></p>
        </div>";

    endif;

    $replyTo =   "Reply-To: ".$email;
    $headers = array(
        'Content-Type: text/html; charset=UTF-8',
        $replyTo
    );

    file_put_contents("mail.html", $message);

    $sent = wp_mail($to, $subject, $message, $headers);
    return $sent;
}
php mysql wordpress
1个回答
1
投票

您有错字:

global $wbpd; //global $wpdb;
© www.soinside.com 2019 - 2024. All rights reserved.