1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with Contact Form

Discussion in 'General Scripting Chat' started by chronic420, Jul 21, 2013.

  1. chronic420

    chronic420 Newbie

    Joined:
    Jul 7, 2013
    Messages:
    21
    Likes Received:
    4
    Occupation:
    Grower
    Location:
    Aussie
    Gday peeps.. im fairly new around here and slowly building a few websites, was wondering if any1 can help with sum issues im having with my contact submit page it wont email..

    im sure i need a extra php or sumthing.. anyways if any1 can help me ill be very gratefull can return the favour with yelp reviews or what not..cheers n beers;) pm me me
     
  2. Gogol

    Gogol Elite Member

    Joined:
    Sep 10, 2010
    Messages:
    3,062
    Likes Received:
    2,872
    Gender:
    Male
    See this for example....
    Code:
    <?php
    if (isset($_POST['submit_button'])) {
    
        $yourname = isset($_POST['yourname']) ? $_POST['yourname'] : '';
        $youremail = isset($_POST['youremail']) ? $_POST['youremail'] : '';
        $yourcomment = isset($_POST['yourcomment']) ? $_POST['yourcomment'] : '';
    
        $total_content = "A new contact received from {$yourname}. \r\n";
        $total_content .= "email address :  {$youremail}\r\n";
        $total_content .= "Comment :  {$yourcomment}\r\n";
    
        $to = 'theemailaddress@whereyouwanttoreceivethemail.com';
        $subject = "Your cool subject!";
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
        $headers .= 'From: <yourname@example.com>' . "\r\n";
    
       // @ supresses the error. You can still have the return in status
        $status = @mail($to, $subject, $total_content, $headers);
    }
    ?>
    <html>
        <form name="yourform" action="" method="post">
    <?php if (isset($status)) {
        if ($status) {
            ?>
                    Message sent successfully
                    <?php } else {
                    ?>
                    Could not send the mail. Are you sure, the mail function is enabled on your server?
    
        <?php }
    }
    ?>
            <br/>
            Email: <input type="text" name="youremail"/> <br/>
            Name:<input type="text" name="yourname"/><br/>
            Comments:<textarea name="yourcomment"></textarea>
        <br/><input type="submit" value="mailme" name="submit_button"/>
        </form>
    </html>
    
    
    
    Obviously, you need validations and all, but this is the barebone that you can use. Hope it helps you and all others searching how to send a mail. Enjoy...
     
    Last edited: Jul 21, 2013
  3. chronic420

    chronic420 Newbie

    Joined:
    Jul 7, 2013
    Messages:
    21
    Likes Received:
    4
    Occupation:
    Grower
    Location:
    Aussie
    thanks mate cheersss