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.

Simple contact form?

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

  1. #1
    Hi there,

    just after some extremely simple php code for a contact form that emails the details to an email address and then says "thank you etc"

    Cheers:cool:
     
    Solved! View solution.
    le007, Oct 14, 2011 IP
  2. Mak3MyDay

    Mak3MyDay Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It's actually quite simple if you have experience a little experience in php...
    You can create a simple contact form and then for the emailer, you can use this:
    http://www.w3schools.com/php/php_mail.asp
     
    Mak3MyDay, Oct 15, 2011 IP
  3. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Will give it a lash, Mak3MyDay. Cheers for the link ",)
     
    le007, Oct 15, 2011 IP
  4. DavidWincent

    DavidWincent Peon

    Messages:
    119
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It is very simple to create contact form using PHP. Only few lines of codes is required. Some online tutorials are very helpful to guide stepwise to create contact form.
     
    DavidWincent, Oct 18, 2011 IP
  5. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    I'm struggling here David. I'm a CSS man :/
     
    le007, Oct 18, 2011 IP
  6. kristenmorey111

    kristenmorey111 Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    make a contact form in html using dreamweaver...and give proper naming to all input and create a submit button

    now you can follow the link www(dot)w3schools(dot)com/php/php_mail.asp ...if you need any help regarding coding then let us know.
     
    kristenmorey111, Oct 19, 2011 IP
  7. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #7
    Hi Kristenmorey111,

    I placed this on my contact.php page but I'm getting an error saying "failed to connect to smtp" etc, any ideas?

    <?php
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email
    {
    //send email
    $email = $_REQUEST['email'] ;
    $subject = $_REQUEST['subject'] ;
    $message = $_REQUEST['message'] ;
    mail("my@email.com", "$subject",
    $message, "From:" . $email);
    echo "Thank you for using our mail form";
    }
    else
    //if "email" is not filled out, display the form
    {
    echo "<form method='post' action='contact.php'>
    Email: <input name='email' type='text' /><br />
    Subject: <input name='subject' type='text' /><br />
    Message:<br />
    <textarea name='message' rows='15' cols='40'>
    </textarea><br />
    <input type='submit' />
    </form>";
    }
    ?>
     
    le007, Oct 20, 2011 IP
  8. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #8
    Hi all, I uploaded it and it works fine online but no email is being sent? No error appears "your email has been sent" appears but it doesn't go into my inbox? No spelling mistakes or anything :/

    I've 2 files, contact.php and sentcontact.php - any suggestions please? Thanks
     
    le007, Oct 20, 2011 IP
  9. kristenmorey111

    kristenmorey111 Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Make sure that your email address is correct...I mean to whomever you wish to send is correct or not.

    mail("my@email.com", "$subject", $message, "From:" . $email);


    mail("proper_email_address@website.com", $subject,$message, "From:" . $email);

    hope it helps
     
    kristenmorey111, Oct 20, 2011 IP
  10. Divided

    Divided Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    3
    Trophy Points:
    0
    #10
    One thing you need to be wary of is email header injection. With the script you have there I could bcc loads of other email addresses in and use your server your spam them.

    Look here for a simple example:

    www(dot)tonyspencer(dot)com/2005/12/15/email-injection-exploit-through-a-php-contact-form/

    If you want a good solution with minimal coding effort look at some of the PHP mailer classes:

    sourceforge(dot)net/projects/phpmailer/

    I don't want to discourage you from creating your own solution but just making you aware of the risks!
     
    Divided, Oct 21, 2011 IP
  11. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #11
    Are you sure your host supports PHP's mail() function? Try
    
    <?php error_reporting(E_ALL);
      $to = 'your.email@address.com';
      if(mail($to, 'Testing mail', 'This is a mailing test to see if PHP mail works.')) {
          echo 'Mail was sent by PHP';
     } else {
          echo 'PHP could not send the mail';
     }
     ?>
    
    PHP:
    (Replace with your email address.) Run the page. (Save it as emailtest.php, for example, then go to http://www.yoursite.com/emailtest.php.) If you don't get the email, contact your hosting company.
     
    Rukbat, Oct 21, 2011 IP
  12. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #12
    Hi everyone,

    thank you for your replies. I only just got a chance to try the php code and it said "Mail was sent by PHP".... AND I got the email....

    SO,

    The question remains, what is wrong with my original code please?
     
    le007, Oct 23, 2011 IP
  13. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #13
    It could be

    "From:" . $email

    It should be

    "From: " . $email

    (There should be a space after the colon.)

    Also

    $email = $_REQUEST['email'] ;

    should be

    
    $email = isset($_REQUEST['email']) ? $_REQUEST['email'] : '';
    if(!$email) {
      //send the user an error and don't try to sent the email
    }
    
    PHP:
     
    Rukbat, Oct 24, 2011 IP
  14. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #14
    Hi Rukbat, thanks for the reply.

    Tried the "From:" . $email

    It should be

    "From: " . $email and that made no difference

    Couldn't find the other part to edit :/

    I really just need something really, really simple - dunno why it won't work.
     
    le007, Oct 24, 2011 IP
  15. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #15
    Without a dump of the full string being sent to the mail() function, it's all guesswork. If you could install Firebug and FirePHP, and learn to use them, and change
    
    mail("my@email.com", "$subject", $message, "From:" . $email);
    
    PHP:
    to
    
    $mail = "my@email.com,$subject,$message, From: $email";
    fb::log($mail);
    mail($mail);
    
    PHP:
    then post the line FirePHP gives you, it would be easier to troubleshoot.
     
    Rukbat, Oct 24, 2011 IP
  16. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #16
    No probs, not at home - will do it when I get there.

    Thank you ",)
     
    le007, Oct 24, 2011 IP
  17. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #17
    Hi Rukbat,

    I did all you said and this appears:

    Class 'fb' not found in the file ??
     
    le007, Oct 27, 2011 IP
  18. WPC

    WPC Peon

    Messages:
    116
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Make sure your host allows mail(), if it doesn't send a mail contact your web host.
     
    WPC, Oct 27, 2011 IP
  19. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #19
    Hi WPC,

    I did try an alternative mail script earlier in this post and it did work but my script won't work - any suggestions please?
     
    le007, Oct 29, 2011 IP
  20. kishanterry

    kishanterry Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #20
    Try the following code:

    $to = 'email_addr@domain.com ';
        $subject = 'Your Subject';
        
        $body = "\r\nYour Mail Body";
        
        $mail_sent = mail($to, $subject, $body);
        echo $mail_sent ? "Mail sent" : "Mail failed";
    PHP:
    It worked for me. It doesn't have "header" information by the way :)
    Cheers
     
    kishanterry, Oct 29, 2011 IP