1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need php script for my contact form

Discussion in 'HTML & Website Design' started by undertaker1, Jan 8, 2013.

Thread Status:
Not open for further replies.
  1. #1
    Hi I got this contact form from a template online. But I've tried so many php scripts online and it doesnt seem to work when I customise it. This is the code for my contact form:
     
    undertaker1, Jan 8, 2013 IP
  2. braingobbler

    braingobbler Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well this form is going to submit to the page that it is one. Not sure what the PHP side of this looks like, which would help to have so we can narrow down the problem.
     
    braingobbler, Jan 8, 2013 IP
  3. undertaker1

    undertaker1 Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Ok so if this is going to submit to the same page, then I am going to need a php script on the same page. I've tried that, I think I did manage to get it working but no text came after name, email, message etc.
     
    undertaker1, Jan 8, 2013 IP
  4. braingobbler

    braingobbler Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hmm Heres a very simple mock up php script

    
    <?php
    
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    
    echo "Name: ".$name."<br/>Email: ".$email."<br/>Message: ".$message;
    
    ?>
    
    Code (markup):
    the code above will just echo what you put in.

    now also your submit button is a button type. I'm guess there is some form validation thats happening and that could actually be making it submit to another page.

    let me know if you can help more. Its just hard when I dont see the entire pages code.
     
    braingobbler, Jan 8, 2013 IP
  5. undertaker1

    undertaker1 Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    I need the code for the echo to be sent to the email. The button is a href link which can be directed to another page. If you want, I can send the files over to you if you can do it.
     
    undertaker1, Jan 8, 2013 IP
  6. braingobbler

    braingobbler Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I don't need the code.

    just put this at the top of the page that it submits to, what ever this page is


    
    <?php 
    
    //this gets the posted information
    $name = $_POST['name'];
    $email = $_POST['email'];
    $contact_message = $_POST['message'];
    
    //this sets up the email that will be sent, replace your email in where it is youremail@something.com. and you can change the subject to whatever you need it to be
    $to = "youremail@something.com";
    $subject = "Contact form";
    $message = "Name: ".$name."\n Email: ".$email."\n Message: ".$contact_message;
    
    mail($to,$subject,$message);
    [COLOR=#111111]
    ?>[/COLOR]
    
    Code (markup):
     
    braingobbler, Jan 8, 2013 IP
  7. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #7
    There's no reason to duplicate the variables unless you're changing them:

    
    $to = "youremail@something.com";
    $subject = "Contact form";
    $message = 'Name: '.$_POST['name']."\n Email: ".$_POST['email']."\n Message: ".$_POST['message'];
    mail($to,$subject,$message);
    
    PHP:
    (Oh - single quotes unless double quotes are actually required.)
     
    Rukbat, Jan 9, 2013 IP
  8. Shaik Murshidul Haque

    Shaik Murshidul Haque Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #8
    hmm. I'm giving you a full script which you can help you.
     
    Shaik Murshidul Haque, Jan 26, 2013 IP
  9. Shaik Murshidul Haque

    Shaik Murshidul Haque Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #9
    <form name="contactform" method="post" action="send_form_email.php">
    <table width="450px">
    <tr>
    <td valign="top">
      <label for="first_name">First Name *</label>
    </td>
    <td valign="top">
      <input  type="text" name="first_name" maxlength="50" size="30">
    </td>
    </tr>
    <tr>
    <td valign="top"">
      <label for="last_name">Last Name *</label>
    </td>
    <td valign="top">
      <input  type="text" name="last_name" maxlength="50" size="30">
    </td>
    </tr>
    <tr>
    <td valign="top">
      <label for="email">Email Address *</label>
    </td>
    <td valign="top">
      <input  type="text" name="email" maxlength="80" size="30">
    </td>
    </tr>
    <tr>
    <td valign="top">
      <label for="telephone">Telephone Number</label>
    </td>
    <td valign="top">
      <input  type="text" name="telephone" maxlength="30" size="30">
    </td>
    </tr>
    <tr>
    <td valign="top">
      <label for="comments">Comments *</label>
    </td>
    <td valign="top">
      <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
    </td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:center">
      <input type="submit" value="Submit">  <a href="http://www.freecontactform.com/email_form.php">Email Form</a>
    </td>
    </tr>
    </table>
    </form>
    HTML:
     
    Last edited by a moderator: Jan 26, 2013
    Shaik Murshidul Haque, Jan 26, 2013 IP
  10. Shaik Murshidul Haque

    Shaik Murshidul Haque Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #10
    and this is your php code.
    <?php
    if(isset($_POST['email'])) {
       
        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "you@yourdomain.com";
        $email_subject = "Your email subject line";
       
       
        function died($error) {
            // your error code can go here
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        }
       
        // validation expected data exists
        if(!isset($_POST['first_name']) ||
            !isset($_POST['last_name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['telephone']) ||
            !isset($_POST['comments'])) {
            died('We are sorry, but there appears to be a problem with the form you submitted.');     
        }
       
        $first_name = $_POST['first_name']; // required
        $last_name = $_POST['last_name']; // required
        $email_from = $_POST['email']; // required
        $telephone = $_POST['telephone']; // not required
        $comments = $_POST['comments']; // required
       
        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
        $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$first_name)) {
        $error_message .= 'The First Name you entered does not appear to be valid.<br />';
      }
      if(!preg_match($string_exp,$last_name)) {
        $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
      }
      if(strlen($comments) < 2) {
        $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      }
      if(strlen($error_message) > 0) {
        died($error_message);
      }
        $email_message = "Form details below.\n\n";
       
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        }
       
        $email_message .= "First Name: ".clean_string($first_name)."\n";
        $email_message .= "Last Name: ".clean_string($last_name)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Telephone: ".clean_string($telephone)."\n";
        $email_message .= "Comments: ".clean_string($comments)."\n";
       
       
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers); 
    ?>
     
    <!-- include your own success html here -->
     
    Thank you for contacting us. We will be in touch with you very soon.
     
    <?php
    }
    ?>
    PHP:
     
    Last edited by a moderator: Jan 26, 2013
    Shaik Murshidul Haque, Jan 26, 2013 IP
  11. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #11
    Wow, don't take this the wrong way guys... ah, what the hell, there's no 'right' way to put this... but if the first bit of code is 'bad', Shaik's examples are even WORSE... tables for layout, idiotic broken scripting doing existing form elements job, tables for layout -- this thread has it all.

    Of course you might get better results asking in the PHP section too.

    First order of business is cleaning up the HTML -- and no, that idiotic table is not the answer.
    
    <form id="contactForm" method="post" enctype="multipart/form-data"> 
    	<fieldset>
    		<label for="contactName">Your Name:</label>
    		<input type="text" name="name" id="contactName" />
    		<br />
    		<label for="contactEmail">Your Email:</label>
    		<input type="text" name="email" id="contactEmail" />
    		<br />
    		<label for="contactMessage">Your Message:</label>
    		<textarea input name="message" id="contactMessage"></textarea>
    	</fieldset>
    	<div class="submitsAndHiddens">
    		<input type="reset" value="Clear" />
    		<input type="submit" value="Send" />
    	</div>
    </form>
    
    Code (markup):
    As to handling it server side, I'm away from the workstation but I'll try to remember to revisit this when I'm at the workdesk.
     
    deathshadow, Jan 26, 2013 IP
  12. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #12
    Does not appear to be valid? How about checking the MX and/or A records of the email domain and find out whether it is a valid email domain. (Then you can try to ask the server if the account is valid, although most servers won't tell you any more.) Doing a RegEx for email verification fails as soon as a new email address format comes out. will fail your "verification", and there's no guarantee that they won't come out with a tld like that. Changing your RegEx to {2,7} will pass a lot of invalid typos. (Even {2,4} will. amazon.xom is a typical typo, and you'd pass it, even though there's no such address on the internet.)
     
    Rukbat, Jan 26, 2013 IP
  13. signorm68

    signorm68 Well-Known Member

    Messages:
    984
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #13
    If you are beinner in php, try this nice tutorial:
    http://www.html-form-guide.com/contact-form/php-email-contact-form.html
    or use free contact forms in cloud (no job at all)
    http://cloudcontactforms.com/
     
    signorm68, Jan 27, 2013 IP
  14. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #14
    Ahh, tables never get any respect anymore. I still sometimes use them since my HTML skills are from 1999. (there wasn't a party like it, either)
    Everything is here in this post says deathshadow except: Invest in my idea, we'll each put in a million dollars and ride around on a tour bus with porn stars in search of Spock.

    We're all programmers and we're all pissed off.. we didnt get the $100k plus^ for work at home skills like they promised in the cliche' propaganda. I should have been a rocket scientist at least that way I could revive rocket mail now that the post office is going under. We should build a website called Israel and have a social network with little yamikas for avatars. Nobody would give us negative pitch. (etches equations on multiple chalkboards....it's not true, banana peels DON'T work in the fLux Capacitor and seems to be whats causing it to not work. *slaps random bystander*
     
    ezprint2008, Jan 27, 2013 IP
  15. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #15
    They get plenty of respect when used properly: for tabular data; but using them for no good reason apart from being presentational markup and code bloat is like calling an ox a bull; he appreciates the honor, but he'd much rather have restored what is rightfully his.

    With tables around forms for NOTHING (doing inline-block's job on the labels), and most people crapping out tables being blissfully unaware of two-thirds the tags one should use in tables like THEAD, TBODY, TH, CAPTION and the important attributes like SCOPE that form the relationship between TH and the row/column they are in...

    Though at least Shaik's example wasn't this idiocy we see ALL the damned time:
    <td><center><b>First Name:</b></center></td>

    Since I whip up the knife-hand ready to pimp slap every time I see that. For the ignorant and unaware, PROPERLY that would be
    <th scope="row">First Name:</th>

    NOT that in this case, it should be a table element AT ALL... it should be JUST the labels and inputs with no extra tags apart from line-breaks.

    
    label {
      display:inline-block;
      text-align:right;
      width:12em;
    }
    
    Code (markup):
    Say it once in the CSS, not every blasted time in the markup... and look ma, no floats.

    -- edit -- P.S. Thanks for the bump, I'll belt out a working demo code on my next break on how I'd approach this.
     
    Last edited: Jan 27, 2013
    deathshadow, Jan 27, 2013 IP
  16. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #16
    whatever works though right?
    If it works and the 'code is bloated' as you say, a few extra MB or KB never brought down a server.
    (even if thousands of pages)
    If it looks good on-page and doesn't lag or crash. It's just a matter of preference.
    calling the ox the bull, its better than if the ox was only a mere chicken to start with and nobody would ever think of it as a bull or an ox, because nobody paid any attention because the chicken simply did not exist in a giant world with ox and bulls.LOL
     
    ezprint2008, Jan 27, 2013 IP
  17. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #17
    And if it lags just a little, it's also just a matter of preference. And if it lags more than just a little ... well, the internet also lags, so who can tell whether it's the site or the internet. And even if it's the site, what's your rush?

    That's the same attitude that sends cars with defective brakes off the assembly line, into the dealers' showrooms and off cliffs. "Good enough is good enough." It's not. We didn't climb down from the trees by "good enough".
     
    Rukbat, Jan 27, 2013 IP
  18. Nick Son

    Nick Son Member

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    41
    #18
    ps: I used captcha for this form, you can remove it. if you need captcha, please tell me
     
    Nick Son, Jan 28, 2013 IP
  19. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #19
    Rukbat,
    The Internet today isn't going to lag from a file with tables, the same way it didn't on dial-up in 1999. LOL But it's good to see you're flying around to save the .004 cpu response of the Internet. That was quite an image-bolster post for yourself. Now we're all to assume you are a NASA expert or something. I wasn't making a statement that people verbally crapped on for using tables is a joke. Tables work and so does anything else. Most of the HTML editors and programs still use tables so can you direct your assault at the program makers and editors as well? There's really no money in developing HTML sites with tables or not anyway. So its a mute point. I'm a PHP programmer and there's barely any money in that field let alone HTML. I know what I'm talking about in industries and markets since I'm also a US National Publisher Inc. (music publishing/lyrics/poetry)of US recording artists that have been rated #1 in US at FM radio/industry. A record company owner/entrepreneur.Marketing,promotions, recording engineer, producer. With 12 songs awarded. I know the difference between what perfected work is and what's not. Using tables is a preference thing and when they come out with HTML Version 10 you'll be verbally crapped on for using your labels. Pagination issues tend to not be <tables> related. You're free to your opinion of tables though. What helps is if you can add proof to your tables religion. Show us proof that tables are laggy and bad. We've all heard the stories but is there any valid proof and if so what is the lag/pagination issues we're talking about?
     
    ezprint2008, Jan 28, 2013 IP
  20. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #20
    I rarely use the bandwidth or CPU claim -- sometimes it's less code, sometimes it's more; but when people go nutters doing idiocy like white-space stripping to cut out 300 to 600 bytes, when you can cut out 30% of most every line or more often 70% of the total markup people use to build sites JUST by not using tables for layout... It really calls into question the rationality of the developers who won't pull their heads out of 1997's arse.

    The CPU part? Yeah, that's BS. If a 384/40 running IE4 on windows 3.1 can 'render' a table in an acceptable amount of time, its' a BS claim in the age of multi-ghz multi-core computing.

    When it's non-semantic markup that prevents you from properly doing responsive layout, accessible layout for screen readers, and non-semantic layout screwing up things like heading navigation, and leveraging separation of presentation from content

    Oh hell yeah, crap on them from ORBIT... since by "editor" I assume you mean some idiotic bloated rubbish WYSIWYG, which no rational developer who actually cares about usability, accessibility, or cost of hosting would be DUMB ENOUGH to use! But sure, go ahead, throw 150k of non semantic markup at 10k of content.

    1) The word is Moot... The point can speak for itself just fine. Interestingly the word shares etymology with 'meet', more specifically a 'landsmeet'.

    2) Further proof that most PHP programmers don't know enough HTML to be using PHP in the first place; since it's a hypertext preprocessor it might help if you actually understood what it is you're supposed to be preprocessing.

    Ok, do a responsive layout using tables -- browse a website that's non-tabular data that's table based with a screen reader some time... How about some simple math that most table based layouts end up two or three times the markup they would be as minimalist semantic markup with separation of presentation from content?

    Tables for layout was HTML 3.2 style abuse of the entire reason HTML exists (along with all the other garbage like redundancies and presentational tags that were deprecated or made obsolete) -- semantic device neutral delivery of content; this is why the proper approach to web development via HTML 2 and 4 is to semantically markup your content FIRST (Saying what things ARE, not how they are going to look on screen), then create your layoutS in CSS, then and only then go into the goofy paint program to make the graphics to hang on that layout. (and yes, layouts is PLURAL)

    Tables for layout is presentational markup -- garbage that has NO business in HTML to begin with. You are supposed to say what things ARE so the user agent (browser) can best determine how to show it -- if you want to customize the appearance for specific media targets, that's CSS' job. What's three columns on one device could be two columns on another or one column on yet another -- responsive layout, the next logical step after things like McSwitchy and fluid/elastic design.

    Of course as I've said a million times, if all one does is crap out inaccessible fixed width layouts with inaccessible undersized fixed metric (px) fonts, and only ever worked with presentational markup these may as well be alien concepts -- so enjoy making MORE WORK for yourself by using more code for no good reason.
     
    Last edited: Jan 28, 2013
    deathshadow, Jan 28, 2013 IP
Thread Status:
Not open for further replies.