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

时间:2019-11-25 11:53:32

标签: php mysql wordpress

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

代码如下:

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

    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;
}

1 个答案:

答案 0 :(得分:1)

您有错字:

global $wbpd; //global $wpdb;