Simple contact form?

Discussion in 'PHP' started by le007, Oct 14, 2011.

  1. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #21
    Hi Kishanterry,

    Thank you for your reply. Your code works, at least I can get an email but no details get through? I've included both files - maybe you can find the error. Thank you.

    contact.php

    <form name="form1" method="post" action="send_contact.php">
    
    <br>
    
    <div>
    <p>
    <label>Name:</label><br>
    <input type="text" style="color: #37383D; background-color: white;"  name="subject" type="text" id="subject" value="" size="60" />
    </p>
    
    <p>
    <label>Telephone:</label><br>
    <input type="text" style="color: #37383D; background-color: white;" name="name" type="text" id="name" value="" size="60" />
    </p>
    
    <p>
    <label>Email Address:</label><br>
    <input type="text" style="color: #37383D; background-color: white;" name="customer_mail" type="text" id="customer_mail" value=""  size="60"/>
    </p>
    
    <p>
    <lable>Comment:</label><br>
    <textarea rows="6" cols="45" style="color: #37383D; background-color: white;" name="detail" id="detail"></textarea>
    </p>
    
    <br><p style="margin-left: 100px">
    <Input type="submit" name="Submit" style="color: white;background: #6C7079; width: 80px; border: 1px solid #B9C0CA;font-family: arial; font-size: 11px ;height: 26px;" value="Send Email">
    <Input type="reset" name="send_mail" style="color: white;background: #6C7079; width: 80px; border: 1px solid #B9C0CA;font-family: arial; font-size: 11px ;height: 26px;" value="Reset"></p>
    </form>
    </div>
    PHP:
    send_contact.php
    <div>
    <?php
    
    // Contact subject
    $subject ="$subject";
    // Details
    $body="$detail";
    
    
    $to = 'le007@myemailaddress.com ';
        $subject = 'Contact Form';
     
       
        $mail_sent = mail($to, $subject, $body);
        echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>
    
    </div>
    PHP:

    I'm just receiving a blank email?
     
    le007, Oct 29, 2011 IP
  2. kishanterry

    kishanterry Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #22
    Hi le007,

    Modify the following code:

    to:

    
    $body = $_POST['detail'];
    
    PHP:
    and try to send the mail. And if that works append the rest of the form fields to the $body variable according to your tastes and preferences.

    Cheers
     
    kishanterry, Oct 31, 2011 IP
  3. kellyphong

    kellyphong Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #23
    it is usually good practice to end your header part with \r\n

    for examples;

    $headers = "From: \r\n";

    mail( 'someone@somewhere.com', 'the subject', 'the body', $headers);
     
    kellyphong, Oct 31, 2011 IP
  4. suryawl

    suryawl Peon

    Messages:
    54
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #24
    agree with kishanterry. you need to add $_POST. $body is just empty without that
     
    suryawl, Nov 1, 2011 IP
  5. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #25
    Woohoo !
    Winner, winner, chicken dinner!

    Excellent, thanks very much kishanterry, kellyphong, suryawl and everyone else who posted to this thread.
    Finally, it worked - I will duplicate it for the rest but yes, the details went through successfully ",)
     
    le007, Nov 1, 2011 IP
  6. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #26
    Eek, may have spoken too soon - tried to change the subject and got an error:

    The code for my form is still the same as my previous above comment - would somebody please kindly change what it needed so that I can get the name, telephone, email and details sent ",)

    Thank you very much.
     
    Last edited: Nov 1, 2011
    le007, Nov 1, 2011 IP
  7. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #27
    Last shot effort and it's not working ?

    <?php
    
    // Contact subject
    $name ="$_POST['subject'];
    // Details
    $tele = $_POST['name'];
    
    $email = $_POST['customer_mail'];
    
    $body = $_POST['detail'];
    
    
    $to = 'myemail@gmail.com ';
        $subject = 'Contact Form';
     
       
        $mail_sent = mail($to, $subject, $name, $tele, $email, $body);
        echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>
    
    PHP:
     
    le007, Nov 1, 2011 IP
  8. #28
    Hi le007,

    Try the following:

    
    $body = "Name: " . $_POST['subject'] . "\r\nTelephone: " . $_POST['name'] . "\r\nE-mail: " . $_POST['customer_email'];
    $body .= "\r\nDetails:\r\n" . $_POST['detail'];
    
    $to = 'myemail@gmail.com ';
    $subject = 'Contact Form';
      
    $mail_sent = mail($to, $subject, $body);
    echo $mail_sent ? "Mail sent" : "Mail failed";
    
    PHP:
    There we two problems in your code (as far as I know):

    1.
    $name ="$_POST['subject'];
    PHP:
    The quote (") in front of $_POST... is a syntax error.

    2. And the mail() function was taking too many parameters.
     
    kishanterry, Nov 1, 2011 IP
  9. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #29
    Hi Kishanterry,
    Thanks a million for your reply and all the help. You really have helped me out here! It's working precisely how I'd like it to.

    Appreciate it!
    Le007 :cool:
     
    le007, Nov 2, 2011 IP
  10. kishanterry

    kishanterry Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #30
    Hi le007,

    Happy to help.

    I believe you are a CSS person. Could you please look into my problem and see if you could help me. Unfortunately I am not allowed to post links, but the precise title of my post is Overriding td height="?" using CSS.

    Thanks in advance.
     
    kishanterry, Nov 3, 2011 IP
  11. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #31
    No problem Kishanterry, will do :D
     
    le007, Nov 3, 2011 IP