php - wordpress:在发送电子邮件时将字段保存到数据库 - 错误 500
问题描述
我正在尝试将提交表单的内容保存到数据库表中。但是当我提交表单时,我收到错误 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;
推荐阅读
- reactjs - 如何在反应js中隐藏和显示一个div
- rest - 如何确定 REST url 在 Delphi REST 服务器中是否包含 HTTPS?
- maximo-anywhere - IBM Maximo Anywhere 中的路由工作流
- python - Pandas,Geopandas.- 空间连接操作
- typo3 - TYPO3 9.5 LTS - 使用 routeEnhancers 配置自定义 PAGE 类型
- mysql - 为什么 MySQL 在没有 group by 语句的情况下给我一些聚合函数的结果
- python - 如何在python中有效地运行并行进程,而每个进程都应该从一个大文件中读取
- python - 使用 CMake 在 Windows 10 上简单地安装 ITK Elastix 以在 Python 中运行
- azure - Azure 指标观察到的指标值与 Auto Scaling 的实际指标值
- django - 'ForwardManyToOneDescriptor' 对象没有属性 'all