Skip to content

Instantly share code, notes, and snippets.

@asllanmaciel
Created August 18, 2021 00:31
Show Gist options
  • Save asllanmaciel/45cb2482eb4c1251ced2d652fe9599b2 to your computer and use it in GitHub Desktop.
Save asllanmaciel/45cb2482eb4c1251ced2d652fe9599b2 to your computer and use it in GitHub Desktop.
Insert Contact Form 7 Submissions (WordPress) in External DB with PHP/MySQL
<?php
//Use in theme functions.php
function save_db($cf7){
$submission = WPCF7_Submission::get_instance();
if($submission){
$posted_data = $submission->get_posted_data();
}
if($cf7->id() == 55){
$con = mysqli_connect('localhost','root','','test_082021_2');
$sql = "INSERT INTO clientes (nome,email) VALUES (?, ?)";
if($stmt = mysqli_prepare($con, $sql)){
mysqli_stmt_bind_param($stmt, 'ss', $param_nome, $param_email);
$param_nome = $posted_data['your-name'];
$param_email = $posted_data['your-email'];
if(mysqli_stmt_execute($stmt)){
echo '';
}
}
mysqli_stmt_close($stmt);
mysqli_close($con);
}
}
add_action('wpcf7_before_send_mail','save_db', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment