Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

contact form 7 - cannot run php

I have installed WordPress and the plugin contact form 7 in it.

To make it a multi-page contact form I have installed Contact Form 7 Multi-Step Forms as well. Everything works fine until yet. Even the mail gets sent.

The problem I am having is, that I want to run some PHP-code before the emails get sent.

I have inserted this code to try the ability of the plugin to run it.

function testfunc( $cf7 )
{
    mysql_connect("localhost", "user_name", "password") or die(mysql_error());
    mysql_select_db("db_name") or die(mysql_error());
    mysql_query("CREATE TABLE `aaaaaaaaaaa` ( test VARCHAR(30))");
}

add_action( 'wpcf7_before_send_mail', 'testfunc', 1);

The function even works fine when I run it outside of the plugin in an extra php-file.

Now I cannot figure out why the function does not work when inserted in the plugin?

like image 261
Friedrich Avatar asked May 06 '14 07:05

Friedrich


People also ask

Can I use PHP in Contact Form 7?

The Contact Form 7 plugin is great, and works with PHP 8.0 without noticeable issues.

How to use shortcode in contact form 7?

Open the editor page for the contact form you want to add (Contact > Contact Forms). Each contact form has its own shortcode, such as [contact-form-7 id="1234" title="Contact form 1"] . Copy the shortcode and paste it into the content of the post.


1 Answers

Query database in wordpress using it's global wpdb object like this way

Refer this

function testfunc( $cf7 )
{
    global $wpdb;
    $wpdb->query("CREATE TABLE `aaaaaaaaaaa` ( test VARCHAR(30))");
}

add_action( 'wpcf7_before_send_mail', 'testfunc', 1);
like image 169
shyammakwana.me Avatar answered Sep 30 '22 08:09

shyammakwana.me