55 users online (1 members and 54 guests)  


  Results 1 to 14 of 14

Related

  1. Replies: 0
  2. Contact Box Help    Forum: Myspace Forum
    Replies: 1
  3. display fields from contact form    Forum: PHP Forum
    Replies: 1
  1. #1
    HMC's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    php contact form

    Firstly, hello to all and I hope I am posting correctly. If I can get some help I would appreciate, can't give make at mo with regards to php but if i get there, sure will.
    Basically, have self taught via books/net and need to do php script for contact form. Confused as so much help out there for php/htm together and not for php in script alone. Basically can you direct me to a tutorial or answer, does it matter what goes where in order on a script? i.w., does security code go before submit button code, i hope i make sense, written a script but is there anywhere i can follow to make sure it's ok before running? Hope I'm not asking too much.

    Thank you
    H
    Last edited by vinyl-junkie; 05-10-2007 at 09:32 PM. Reason: Added a meaningful thread title

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Help with PHP Contact Form

    Welcome to AHFB!

    Is this a contact form script that you've written yourself? If not, most pre-made scripts usually come with some setup instructions. If it's one you've written yourself, the main thing to remember is to populate the appropriate variables, massage the input data to make sure your contact form isn't used as a relay for spam, and to send the email. Beyond that, there isn't much I could say without seeing your code.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    HMC's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    Re: Help for a newbie please

    Thank you for a prompt reply. It's one I'm trying to write myself as trying learn php. But I'm having problems with checkboxes, and on spending last night on the net, it seems it can cause problems on sending back? what I want to do is to show in the email the list as per the form but which ones were checked. I started off with

    <?php
    function check OK (£field) etc
    then a list of checkok for the (do you call them variables?) ie name, address, email using post
    then there's a ($_SERVER [RequestMethod] etc
    then if (isset ($POST['submit'])){
    and then mail(and the usual list.

    I do have a submit and reset button, I would post the script but felt that would be asking too much.
    I really do want to learn but am finding all that I come across confusing as it feels like everyone does it slightly different? or have I missed the thread? no pun intended. My host does accept php and has register globals turned off. Thank You for your time. It's appreciated.
    Last edited by DeadMeatGF; 05-11-2007 at 03:53 AM. Reason: Split the text a little for readability!

  4. #4
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Help for a newbie please

    We'd need to see the code itself to help properly (please use [code], [php] etc tag where applicable)

    Looking at the above, if I remember correctly, shouldn't it be $_POST?

  5. #5
    firmaterra's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    81

    Re: Help for a newbie please

    post your script! We all had to start somewhere and we're all nice folk around here!

  6. #6
    HMC's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    Re: Help for a newbie please

    Thank you for reply and for offer. It's very kind of you!
    Shall I just copy and paste into here?
    Many thanks, I must say you are a God Send! I've worked day and night til the wee hours to try and get to grips with this - and my client is expecting results next week!!!
    It's not such a bad world after all!
    Regards
    H

  7. #7
    HMC's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    Re: Help for a newbie please

    Hi,
    Well here is the script. You will say it's a bit all over the place, because I started then didn't finish, because hence by post to you I got confused, what I haven't put in yet is the textboxes - would these be under variables? with $_POST ? I read somewhere that if you wanted them all returned showing which ones were checked by the user, this can be difficult??
    Don't laugh - here it is! Many many thanks again.

    Code:
    <?php
    function checkOK($field)
    {
    if (eregi("\r",$field) || eregi("\n",$field)){
    die("Invalid Input!");
    }
    }
    $name=$_POST['name'];
    checkOK($name);
    $email=$_POST['email'];
    checkOK($email);
    $comments=$_POST['company'];
    checkOK($company);
    $comments=$_POST['address'];
    checkOK($address);
    $comments=$_POST['telno'];
    checkOK($telno);
    $comments=$_POST['message'];
    checkOK($message);
    $to="enquiries@futureitsystems.co.uk";
    $message="$name just filled in your comments form. They said:\n$message\n\nTheir e-mail address was: $email";
    if(mail($to,"Comments From Your Site",$message,"From: $email\n")) {
    echo "Thank you for your enquiry, we will contact you shortly.";
    } else {
    echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
    }
       if ($_SERVER['REQUEST_METHOD'] != 'POST'){
          $me = $_SERVER['PHP_SELF'];
    } else {
          error_reporting(0);
       
       if(isset($_POST['submit'])) { 
       mail($to,$subject,$body,$headers);
       $to = ‘enquiries@futureitsystems.co.uk';
          $address = stripslashes($_POST['address']);
       $subject = "contact message";
          $from = stripslashes($_POST['name']);
          $msg = "Message from: $from\n\n".stripslashes($_POST['message']);
         
         foreach($_POST ['check'] as $value){
         $check_msg = "Checked: $value\n";
         }
         $body = "From:$name_field\n Email:$email_field\n message:\n$check_msg";
     
          if (mail($recipient, $subject, $msg))
             echo nl2br("<b>Message Sent:</b>
             To: $recipient
             Subject: $subject
             Message:
             $msg");
          else
             echo "Message failed to send";
      $errors = array();
    $page = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
       if (!ereg($page, $_SERVER['HTTP_REFERER']))
          $errors[] = "Invalid referer\n";
       // check to see if a name was entered
       if (!$_POST['name'])
          // if not, add that error to our array
          $errors[] = "Name is required";
       // check to see if a subject was entered
       if (!$_POST['Subject'])
          // if not, add that error to our array
          $errors[] = "Subject is required";
       // check to see if a message was entered
       if (!$_POST['MsgBody'])
          // if not, add that error to our array
          $errors[] = "Message body is required";
       // if there are any errors, display them
       if (count($errors)>0){
          echo "<strong>ERROR:<br>\n";
          foreach($errors as $err)
            echo "$err<br>\n";
       } else {
          // no errors, so we build our message
    
          $recipient = 'user@example.com';
          $from = stripslashes($_POST['Name']);
          $subject = stripslashes($_POST['Subject']);
          $msg = "Message sent by $from\n
             ".stripslashes($_POST['MsgBody']);
          if (mail($recipient,$subject,$msg))
             echo "Thanks for your message!";
          else
             echo "An unknown error occurred.";
       }
       
    if(get_magic_quotes_gpc()){
       foreach($_POST as $name => $value){
          $_POST[$name] = stripslashes($value);
       }
       foreach($_GET as $name => $value){
          $_GET[$name] = stripslashes($value);
       }
    }
    >?php
    Last edited by vinyl-junkie; 05-11-2007 at 09:13 PM. Reason: Added code tags

  8. #8
    HMC's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    Re: Help for a newbie please

    PS Sorry, I think I left the email address in which I shouldn't have. Apologies.

  9. #9
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Help for a newbie please

    I've not had time to pick through this, but purely on syntax, you're missing at least two closing curly braces, and have a number of if ... else statements that don't use them at all.

  10. #10
    firmaterra's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    81

    Re: Help for a newbie please

    Also your closing php tag:

    >?php

    should be:
    ?>

  11. #11
    firmaterra's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    81

    Re: Help for a newbie please

    and try replace this section below. I've included the curly braces for you.

    else
    {
    // no errors, so we build our message
    $recipient = 'EMAIL REMOVED - Send PM to This User Instead';
    $from = stripslashes($_POST['Name']);
    $subject = stripslashes($_POST['Subject']);
    $msg = "Message sent by $from\n
    ".stripslashes($_POST['MsgBody']);
    if (mail($recipient,$subject,$msg))
    {
    echo "Thanks for your message!";
    }
    else
    {
    echo "An unknown error occurred.";
    }
    }

  12. #12
    HMC's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    Re: Help for a newbie please

    Thanks for the reply and taking the time, taken replies on board. If I'm using if else too much what should this proceed so I know what to look for. Is it ..do this, if else etc.? Also at the top you see I've put $name=$_POST['name'];
    checkOK($name); do I continue this format for all boxes, of what is the way for list boxes and checkboxes because I'm getting confused?? Please point me in the right direction. Many thanks again to all.

  13. #13
    HMC's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    Re: Help for a newbie please

    Thanks for the replies and noted. However, do you think all is in the right place and seems ok? So I have to check the if else statements and see if some are unwanted? Also I'm trying to put in checkboxes/lists are these formatted differently if so can you point me in the right direction please? am I right in assuming you don't use the following for checkboxes/lists?
    $name=$_POST['name'];
    checkOK($name);

  14. #14
    teeq's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    2

    Re: Help for a newbie please

    Thank you



Tags for this Thread