php contact form help

Hello everyone,

I’m new to this form so i will apologise in advance if im posting / do anything wrong.

Would it be possible for someone to help me with the php code for my contact page? I just want it to send the compleated form to an outlook email address but im having no luck with it. The website host supports php on the server but everything ive tried so far hasnt worked, i dont get any error messages when the submit buttom is pressed but i dont receive any emails from the contact form.

Can someone help me start the php file from scratch please?

This is the html code for my contact form:

[php]


<input name=“name” id=“name” value=""
                placeholder="Name" type="text"> </div>
            <div class="6u$ 12u$(xsmall)"> <input name="email" id="email" value=""

                placeholder="Email" type="email"> </div>
            <div class="6u 12u$(small)"> <input id="copy" name="copy" type="checkbox">
              <label for="copy">Email me a copy of this message</label> </div>
            <div class="6u$ 12u$(small)"> <input id="human" name="human" checked="checked"

                type="checkbox"> <label for="human">I am a human and not a
                robot</label> </div>
            <div class="12u$"> <textarea name="message" id="message" placeholder="Enter your message" rows="6"></textarea> </div>
            <div class="12u$">
              <ul class="actions">
                <li><input name="submit" value="Send Message" type="submit"></li>
                <li><input value="Reset" class="alt" type="reset"></li>
              </ul>
            </div>
          </div>
        </form>[/php]

Thank you for any help you can provide.

Regards

Jon

I would recommend using Google Recaptcha (https://www.google.com/recaptcha/intro/) instead of your own and use a third party emailer PHPMailer or Swiftmailer (I use this -> https://swiftmailer.symfony.com/)

Here an old example of a contact form that I did :
[php]<?php
require_once ‘…/private/initialize.php’;
use Library\Database\Database as DB;
use Library\Email\Email;
$db = DB::getInstance();
$pdo = $db->getConnection();
$submit = filter_input(INPUT_POST, ‘submit’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if (isset($submit) && $submit === ‘submit’) {
$token = filter_input(INPUT_POST, ‘token’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if (!empty($token)) {
if (hash_equals($_SESSION[‘token’], $token)) {
/* The Following to get response back from Google recaptcah /
$url = “https://www.google.com/recaptcha/api/siteverify”;
$remoteServer = filter_input(INPUT_SERVER, ‘REMOTE_ADDR’, FILTER_SANITIZE_URL);
$response = file_get_contents($url . “?secret=” . PRIVATE_KEY . “&response=” . \htmlspecialchars($_POST[‘g-recaptcha-response’]) . “&remoteip=” . $remoteServer);
$recaptcha_data = json_decode($response);
/
The actual check of the recaptcha */
if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) {
$data[‘name’] = filter_input(INPUT_POST, ‘name’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[‘email’] = filter_input(INPUT_POST, ‘email’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[‘phone’] = filter_input(INPUT_POST, ‘phone’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[‘website’] = filter_input(INPUT_POST, ‘website’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[‘reason’] = filter_input(INPUT_POST, ‘reason’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data[‘comments’] = filter_input(INPUT_POST, ‘comments’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$send = new Email($data);
} else {
$success = “You’re not a human!”; // Not of a production server:
}
} else {
// Log this as a warning and keep an eye on these attempts
}
}
}
require_once ‘…/private/includes/header.inc.php’;
?>

    <fieldset>

        <legend><?php echo (isset($success)) ? $success : 'Contact Form'; ?></legend>
        <input type="hidden" name="token" value="<?= $_SESSION['token']; ?>">
        <label for="name" accesskey="U">Name</label>
        <input name="name" type="text" id="name" tabindex="1" autofocus required="required" />

        <label for="email" accesskey="E">Email</label>
        <input name="email" type="email" id="email" tabindex="2" required="required" />

        <label for="phone" accesskey="P" >Phone <small>(optional)</small></label>
        <input name="phone" type="tel" id="phone" tabindex="3">

        <label for="website" accesskey="W">Website <small>(optional)</small></label>
        <input name="website" type="text" id="website" tabindex="4">

        <div class="radioBlock">
            <input type="radio" id="radio1" name="reason" value="message" tabindex="5" checked>
            <label class="radioStyle" for="radio1">message</label>
            <input type="radio" id="radio2" name="reason" value="order">
            <label class="radioStyle" for="radio2">order</label>  
            <input type="radio" id="radio3" name="reason" value="status">
            <label class="radioStyle" for="radio3">status inquiry</label>    
        </div>

        <label class="textBox" for="comments">Comments</label>
        <textarea name="comments" id="comments" spellcheck="true" tabindex="6" required="required"></textarea> 
        <div class="g-recaptcha" data-sitekey="6LfPlQoUAAAAAPgD3PpnQ_uGTzc87UALiFgQ3XnK"></div>
        <input type="submit" name="submit" value="submit" tabindex="7">
    </fieldset>
</form>
<?php require_once '../private/includes/footer.inc.php';[/php]

You can find more here https://github.com/Strider64/Slice-of-Technology which is a Github Repository that I have done.

Sponsor our Newsletter | Privacy Policy | Terms of Service