【发布时间】:2020-06-01 13:14:27
【问题描述】:
我已经复制了关于contact form 7 wordpress的代码,目前数据已经成功发送到外部数据库,但是消息成功几乎没有显示以及我已经移动到感谢页面。谢谢
function wpcf7_send_to_external ( $cf7 ) {
//external db details
$username = 'username';
$password = 'pass';
$database = 'database';
$host = 'myip';
//create new wpdb instance
$mydb = new wpdb($username, $password, $database, $host);
$cf7 = WPCF7_ContactForm::get_current();
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
$field1 = $data["name"];
$field2 = $data["semail"];
$field3 = $data["phone"];
$field4 = $data["nhu"];
//insert into external db
$mydb->insert(
'customer',
array(
'name' => $field1,
'email' => $field2,
'phone' => $field3,
'content' => $field4
),
array(
'%s','%s','%s','%s'
)
);
}
add_action("wpcf7_before_send_mail", "wpcf7_send_to_external");
【问题讨论】:
-
如果您想将字段存储在联系表单中,则可以使用插件。例如:wordpress.org/plugins/contact-form-cfdb7 它会以正确的方式为您完成工作。
标签: php wordpress contact-form-7