Skip to main content
deleted 43 characters in body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

My HTMLTML:

I was planning on moving everything above the opening ""section> tag into a "header.php" file and including it and everything below the closing ""</section> tag into a "footer.php" file and including it. Just a thought.

My "contactcontact.js" filejs:

NotI'm not sure if I should have a p tag for an error, but let me know.

My email.php: file:

I know my phpPHP needs a lot of work, so I would love input on how to structure this correctly.

Anyhow, please Please let me know of anany structuring, syntax, or best practices I could change anywhere in my code.

Thank you.

My HTML:

I was planning on moving everything above the opening "" tag into a "header.php" file and including it and everything below the closing "" tag into a "footer.php" file and including it. Just a thought.

My "contact.js" file:

Not sure if I should have a p tag for an error, but let me know.

My email.php file:

I know my php needs a lot of work, so I would love input on how to structure this correctly.

Anyhow, please let me know of an structuring, syntax, or best practices I could change anywhere in my code.

Thank you.

TML:

I was planning on moving everything above the opening section> tag into a "header.php" file and including it and everything below the closing </section> tag into a "footer.php" file and including it. Just a thought.

contact.js:

I'm not sure if I should have a p tag for an error, but let me know.

email.php:

I know my PHP needs a lot of work, so I would love input on how to structure this correctly. Please let me know of any structuring, syntax, or best practices I could change anywhere in my code.

deleted 51 characters in body
Source Link
bee
  • 159
  • 7
<?php

//email variables
$to = "[email protected]";
$body = "";
$subject = "";
$headers = "From: [email protected]";

//form fields
$name   = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email  = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$phone  = preg_replace('/[^0-9]/', '', $_POST['phone']);
$business = filter_var($_POST['business'], FILTER_SANITIZE_STRING);
$project = filter_var($_POST['project'], FILTER_SANITIZE_STRING);
$budget = $_POST['budget'];
$audience =filter_var($_POST['audience'], FILTER_SANITIZE_STRING);


/********************************************
 * Check that all fields are filled out     *
 ********************************************/
$errFields = array();

if($name == "") {
    array_push($errFields, "name");
}

if($email == "") {
    array_push($errFields, "email");
}

if($phone == "") {
    array_push($errFields, "phone");
}

if($business == "") {
    array_push($errFields, "business");
}

if($project == ""){
    array_push($errFields, "project");
}

if($budget == "") {
    array_push($errFields, "budget");
}

if($audience == "") {
    array_push($errFields, "audience");
}

//test
array_push($errFields, "budget");

//If something went wrong
if($errFields) {
   echo json_encode(array("success" => False, "error" => $errFields)); 
}
//Send inquiry information to me and response to sender
else {
    /************************
     * Send email to me     *
     ************************/
    $subject = "New Inquire from $business";

    // the message
    $body = <<<EOT
  NAME: $name
  EMAIL: $email 
  PHONE: $phone
  BUSINESS: $email
  PROJECT: $project
  BUDGET: $budget
  AUDIENCE: $audience
EOT;

    // send email to myself
    mail($to, $subject, $body, $headers);


    /************************
     * Send email to sender *
     ************************/
    $to = $email;
    $subject = "Thank you!";
    $body = <<<EOT
 Hi $name,

 Thank you for your recent message!
  
 We look forward to speaking with you soon,
 Beckah
EOT;

    mail($to, $subject, $body, $headers);
    echo json_encode(array("success" => True));
}


?>
<?php

//email variables
$to = "[email protected]";
$body = "";
$subject = "";
$headers = "From: [email protected]";

//form fields
$name   = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email  = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$phone  = preg_replace('/[^0-9]/', '', $_POST['phone']);
$business = filter_var($_POST['business'], FILTER_SANITIZE_STRING);
$project = filter_var($_POST['project'], FILTER_SANITIZE_STRING);
$budget = $_POST['budget'];
$audience =filter_var($_POST['audience'], FILTER_SANITIZE_STRING);


/********************************************
 * Check that all fields are filled out     *
 ********************************************/
$errFields = array();

if($name == "") {
    array_push($errFields, "name");
}

if($email == "") {
    array_push($errFields, "email");
}

if($phone == "") {
    array_push($errFields, "phone");
}

if($business == "") {
    array_push($errFields, "business");
}

if($project == ""){
    array_push($errFields, "project");
}

if($budget == "") {
    array_push($errFields, "budget");
}

if($audience == "") {
    array_push($errFields, "audience");
}

//test
array_push($errFields, "budget");

//If something went wrong
if($errFields) {
   echo json_encode(array("success" => False, "error" => $errFields)); 
}
//Send inquiry information to me and response to sender
else {
    /************************
     * Send email to me     *
     ************************/
    $subject = "New Inquire from $business";

    // the message
    $body = <<<EOT
  NAME: $name
  EMAIL: $email 
  PHONE: $phone
  BUSINESS: $email
  PROJECT: $project
  BUDGET: $budget
  AUDIENCE: $audience
EOT;

    // send email to myself
    mail($to, $subject, $body, $headers);


    /************************
     * Send email to sender *
     ************************/
    $to = $email;
    $subject = "Thank you!";
    $body = <<<EOT
 Hi $name,

 Thank you for your recent message!
  
 We look forward to speaking with you soon,
 Beckah
EOT;

    mail($to, $subject, $body, $headers);
    echo json_encode(array("success" => True));
}


?>
<?php

//email variables
$to = "[email protected]";
$body = "";
$subject = "";
$headers = "From: [email protected]";

//form fields
$name   = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email  = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$phone  = preg_replace('/[^0-9]/', '', $_POST['phone']);
$business = filter_var($_POST['business'], FILTER_SANITIZE_STRING);
$project = filter_var($_POST['project'], FILTER_SANITIZE_STRING);
$budget = $_POST['budget'];
$audience =filter_var($_POST['audience'], FILTER_SANITIZE_STRING);


/********************************************
 * Check that all fields are filled out     *
 ********************************************/
$errFields = array();

if($name == "") {
    array_push($errFields, "name");
}

if($email == "") {
    array_push($errFields, "email");
}

if($phone == "") {
    array_push($errFields, "phone");
}

if($business == "") {
    array_push($errFields, "business");
}

if($project == ""){
    array_push($errFields, "project");
}

if($budget == "") {
    array_push($errFields, "budget");
}

if($audience == "") {
    array_push($errFields, "audience");
}


//If something went wrong
if($errFields) {
   echo json_encode(array("success" => False, "error" => $errFields)); 
}
//Send inquiry information to me and response to sender
else {
    /************************
     * Send email to me     *
     ************************/
    $subject = "New Inquire from $business";

    // the message
    $body = <<<EOT
  NAME: $name
  EMAIL: $email 
  PHONE: $phone
  BUSINESS: $email
  PROJECT: $project
  BUDGET: $budget
  AUDIENCE: $audience
EOT;

    // send email to myself
    mail($to, $subject, $body, $headers);


    /************************
     * Send email to sender *
     ************************/
    $to = $email;
    $subject = "Thank you!";
    $body = <<<EOT
 Hi $name,

 Thank you for your recent message!
  
 We look forward to speaking with you soon,
 Beckah
EOT;

    mail($to, $subject, $body, $headers);
    echo json_encode(array("success" => True));
}


?>
deleted 19 characters in body
Source Link
bee
  • 159
  • 7
$( document ).ready(function() {

    /*****************************************************
     *                Email Form Submission              *
     *****************************************************/

    $("#email-form").submit( function(e) {
        e.preventDefault();
        var $form = $(this);

        $form.validate();

        // check if the input is valid
        if(! $form.valid()) return false;

        //if valid post to email.php
        $.ajax({
            type: "POST",
            url: "email.php",
            data: {
                'name': $('[name="name"]').val(),       
                'email': $('[name="email"]').val(), 
                'phone': $('[name="phone"]').val(),
                'business': $('[name="business"]').val(),
                'project': $('[name="project"]').val(),
                'budget': $('[name="budget"]').val(),
                'audience': $('[name="audience"]').val()
            },
            success: function(data) {
                data = JSON.parse(data);

                //If emailed successfully by backend, replace form with success message
                if( data["success"] == true ) { 
                    $form.html("<h3>Successfully submitted! We'll get back to you soon!</h3>");
                } 
                //If error occurred with any of the fields, put in error message
                else {
                    $('#error-msg').html("Please fix the follow fields:<br />" + data["error"].join("<br />"));
                }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                $form.html("<center><h3>Oh no! :( Something happened</h3>Please let us know at hello@snapwebdevelopmentme@me.com</center>");
            }
        });//EO ajax
    });//EO submit
});
$( document ).ready(function() {

    /*****************************************************
     *                Email Form Submission              *
     *****************************************************/

    $("#email-form").submit( function(e) {
        e.preventDefault();
        var $form = $(this);

        $form.validate();

        // check if the input is valid
        if(! $form.valid()) return false;

        //if valid post to email.php
        $.ajax({
            type: "POST",
            url: "email.php",
            data: {
                'name': $('[name="name"]').val(),       
                'email': $('[name="email"]').val(), 
                'phone': $('[name="phone"]').val(),
                'business': $('[name="business"]').val(),
                'project': $('[name="project"]').val(),
                'budget': $('[name="budget"]').val(),
                'audience': $('[name="audience"]').val()
            },
            success: function(data) {
                data = JSON.parse(data);

                //If emailed successfully by backend, replace form with success message
                if( data["success"] == true ) { 
                    $form.html("<h3>Successfully submitted! We'll get back to you soon!</h3>");
                } 
                //If error occurred with any of the fields, put in error message
                else {
                    $('#error-msg').html("Please fix the follow fields:<br />" + data["error"].join("<br />"));
                }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                $form.html("<center><h3>Oh no! :( Something happened</h3>Please let us know at hello@snapwebdevelopment.com</center>");
            }
        });//EO ajax
    });//EO submit
});
$( document ).ready(function() {

    /*****************************************************
     *                Email Form Submission              *
     *****************************************************/

    $("#email-form").submit( function(e) {
        e.preventDefault();
        var $form = $(this);

        $form.validate();

        // check if the input is valid
        if(! $form.valid()) return false;

        //if valid post to email.php
        $.ajax({
            type: "POST",
            url: "email.php",
            data: {
                'name': $('[name="name"]').val(),       
                'email': $('[name="email"]').val(), 
                'phone': $('[name="phone"]').val(),
                'business': $('[name="business"]').val(),
                'project': $('[name="project"]').val(),
                'budget': $('[name="budget"]').val(),
                'audience': $('[name="audience"]').val()
            },
            success: function(data) {
                data = JSON.parse(data);

                //If emailed successfully by backend, replace form with success message
                if( data["success"] == true ) { 
                    $form.html("<h3>Successfully submitted! We'll get back to you soon!</h3>");
                } 
                //If error occurred with any of the fields, put in error message
                else {
                    $('#error-msg').html("Please fix the follow fields:<br />" + data["error"].join("<br />"));
                }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                $form.html("<center><h3>Oh no! :( Something happened</h3>Please let us know at me@me.com</center>");
            }
        });//EO ajax
    });//EO submit
});
deleted 30 characters in body
Source Link
bee
  • 159
  • 7
Loading
Source Link
bee
  • 159
  • 7
Loading