PHP code example of ttskch / contact-form

1. Go to this page and download the library: Download ttskch/contact-form library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ttskch / contact-form example snippets



// index.php

ContactForm\ContactForm();

// validation targets ("sted, validate csrf and submissions and redirect to next page
$cf->validateAndRedirectAfterSelfPosted('./confirm.php', $


// confirm.php

ntactForm\ContactForm();

// redirect to top page if requested without submissions
$cf->rejectAccessWithoutSubmissions('./index.php');

// after posted, validate csrf and redirect to next page
$cf->validateAndRedirectAfterSelfPosted('./thanks.php');


// thanks.php

ontactForm\ContactForm();

// redirect to top page if requested without submissions
$cf->rejectAccessWithoutSubmissions('./index.php');

$template = <<<EOT
----------------------------------------------------------------------
Name: %s
----------------------------------------------------------------------
Email: %s
----------------------------------------------------------------------
Gender: %s
----------------------------------------------------------------------
EOT;

$body = vsprintf($template, [
    $cf->present('Name', false),
    $cf->present('Email', false),
    $cf->present('Gender', false),
]);

$cf->sendEmail(
    '[email protected]',  // to
    '[email protected]', // from
    'Your Name',      // from name
    'Got inquiry',    // subject
    $body             // body
);

// clear submissions after sending email
// by this, if users reload thanks.php after sending email they will be redirected to index.php 
$cf->clearSubmissions();