Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Simple (not for me simple) PHP Email Form

    I am trying to setup a simple PHP form. It has been years since I've tried to do this and I've looked on the web and I can't seem to get it to work. Here is the email form that was in the HTML5 template I am using. I cannot figure out what the problem is.

    I have the HTML with this code in the same directly as the "send_mail.php" file.

    <form method="post" action="send_mail.php">
    <div class="row half">
    <div class="6u">
    <input name="name" placeholder="Name" type="text" class="text" />
    </div>
    <div class="6u">
    <input name="email" placeholder="Email" type="text" class="text" />
    </div>
    </div>
    <div class="row half">
    <div class="12u">
    <textarea name="message" placeholder="What's on your mind?"></textarea>
    </div>
    </div>
    <div class="row half">
    <div class="12u">
    <input type="image" src="images/sendmessagebutton.jpg">
    <a href="#" class="button button-icon fa fa-envelope">Send Message</a>
    </div>
    </div>
    </form>

    First questions is I added the "<input type="image" src="images/sendmessagebutton.jpg">" because I couldn't get how to make the "<a href="#" class="button button-icon fa fa-envelope">Send Message</a>" act as the submit button. Although, I would rather do that since then it uses the CSS and looks correct.

    So;

    1. how do I get to use a CSS element (in this case "<a href="#" class="button button-icon fa fa-envelope">Send Message</a>") to act as the submit button?

    Second, here is my .php file; send_mail.php

    Again, from an online template;


    <?php
    /*
    This first bit sets the email address that you want the form to be submitted to.
    You will need to change this value to a valid email address that you can access.
    */
    $webmaster_email = "youremail@email.com";

    /*
    This bit sets the URLs of the supporting pages.
    If you change the names of any of the pages, you will need to change the values here.
    */
    $feedback_page = "feedback_form.html";
    $error_page = "error_message.html";
    $thankyou_page = "thank_you.html";

    /*
    This next bit loads the form field data into variables.
    If you add a form field, you will need to add it here.
    */
    $email = $_REQUEST['email'] ;
    $name = $_REQUEST['name'] ;
    $message = $_REQUEST['message'] ;

    /*
    The following function checks for email injection.
    Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
    */
    function isInjected($str) {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str)) {
    return true;
    }
    else {
    return false;
    }
    }

    // If the user tries to access this script directly, redirect them to the feedback form,
    if (!isset($_REQUEST['email_address'])) {
    header( "Location: $feedback_page" );
    }

    // If the form fields are empty, redirect to the error page.
    elseif (empty($email_address) || empty($comments)) {
    header( "Location: $error_page" );
    }

    // If email injection is detected, redirect to the error page.
    elseif ( isInjected($email_address) ) {
    header( "Location: $error_page" );
    }

    // If we passed all previous tests, send the email then redirect to the thank you page.
    else {
    mail( "$webmaster_email", "Feedback Form Results",
    $comments, "From: $email_address" );
    header( "Location: $thankyou_page" );
    }
    ?>

  • #2
    New Coder
    Join Date
    Mar 2005
    Location
    Croatia
    Posts
    20
    Thanks
    1
    Thanked 1 Time in 1 Post
    First questions is I added the "<input type="image" src="http://www.codingforums.com/images/sendmessagebutton.jpg">" because I couldn't get how to make the "<a href="#" class="button button-icon fa fa-envelope">Send Message</a>" act as the submit button. Although, I would rather do that since then it uses the CSS and looks correct.
    An input type="image" only defines that image as the submit button and not as an input that can carry over a value to the server.
    You need to have a type="submit". You can make it look as a button, have no fear. Restore the original html part and if it doesn't have a class, add one to it.

    It should look something like this: <input class="submitbutton" type="submit" value="Send Message" >

    In your css file, add the following:

    .submitbutton {
    font-size: 0;
    text-indent:-9999px; /* <- for ie, earlier versions */
    width: 10000px; /* <- insert sendmessagebutton.jpg width */
    height: 60000px; /* <- insert sendmessagebutton.jpg height */
    border: none;
    margin: 0; /* if needed */
    padding: 0; /*if needed */
    background:url(linktoyourfile/sendmessagebutton.jpg) no-repeat; /* change linktoyourfile relative to the position of css to your image on your server. */
    }


    Also, in your php file, change the actual email address if you haven't already. $webmaster_email = "youremail@email.com";
    Last edited by fixie; 04-04-2014 at 12:57 PM.
    Hit me up for cheap but quality html/css conversions/rebuilds. Ok, let me see what you've got


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •