Contact form in 2 minutes

You just want a fully working contact form, have no more time to spend

That's the right place. Let's start.

  1. You need a php server with php 5.3 or newer running.

    For help, go to Install and run a local PHP server

  2. Add phpformbuilder folder at the root of your project.

    For help, go to Include required files on your page to build form

  3. Copy / paste the following php blocks into your page at the indicated locations :

    <!-- customize (according to the comments) then paste following code at the very beginning of your file  -->
    <?php
    use phpformbuilder\FormExtended;
    
    session_start();
    include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/Form.php';
    include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/FormExtended.php';
    
    // you can change the form name if you want
    $form_name = 'extended-contact-form';
    
    // choose your framework below
    // can be 'bs3', 'bs4', 'material' or 'foundation'
    $framework = 'bs4';
    
    // choose the options for email sending
    $email_config = array(
        'sender_email'     =>  'contact@phpformbuilder.pro',
        'recipient_email'  =>  'john.doe@gmail.com',
        'subject'          =>  'contact from PHP Form Builder'
    );
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        if (FormExtended::validateContactForm($form_name) === true) {
            $sent_message = FormExtended::sendContactEmail($email_config, $form_name);
        }
    }
    
    $form = new FormExtended($form_name, 'horizontal', 'novalidate', $framework);
    
    // this line does the magic form
    $form->createContactForm();
    ?>
    
    <!-- paste following code just before </head> -->
    <?php $form->printIncludes('css'); ?>
    
    <!-- paste following code between <body></body> where your form will be displayed -->
    <?php
    if (isset($sent_message)) {
        echo $sent_message;
    }
    
    $form->render();
    ?>
    <!-- paste following code just before </body> -->
    <?php
    $form->printIncludes('js');
    $form->printJsCode();
    ?>

Your form is ready, email will be sent when form is posted and validated.

If your browser throws an error 500, click button below to solve this.

Your browser has thrown this error because php can't find Form.php.

rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) should lead to the root of your project.
If works fine if your server is well configured, but it seems that's not the case.

To solve this, open ../phpformbuilder/server.php on your browser and follow the instructions.

More explainations about error 500 are available at https://www.phpformbuilder.pro/documentation/help-center.php#warning-include_once