gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 09:29:21 25 4
gpt4 key购买 nike

我正在尝试将提交表单的内容保存到数据库表中。但是,当我提交表单时,我收到错误 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;
}

最佳答案

您有一个拼写错误:

global $wbpd; //global $wpdb;

关于php - wordpress:发送电子邮件时将字段保存到数据库 - 错误 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59031258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com