Results 1 to 9 of 9

Thread: Need Simple contact form

  1. #1
    Join Date
    Dec 2011
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Need Simple contact form

    need a simple contact form
    which has name details etc columns and when the user hits the submit button, i should receive in my email

    thanks

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    try google?

    there are plenty of free scripts out there. try to find one that was written for php5 (older versions are often buggy, incompatible with newer php versions, and/or have security problems).

    if you're looking for someone to write or install a script for you, you should post in the paid help forum.

  3. #3
    Join Date
    Dec 2011
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    tried google but none of them work

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    ?
    do you mean they don't do what you want, or that you couldn't install them successfully?

  5. #5
    Join Date
    Jan 2012
    Location
    India
    Posts
    45
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default

    try to learn not just copy paste

    form.htm
    HTML Code:
    <html>
    <head><title>Form</title>
    </head>
    <body>
    <form name="sendmail" action="sendmail.php" method="post">
    Name:<input type="text" name="name" /><br />
    Email:<input type="text" name="email" /><br />
    <input type="submit" value="Send Mail" />
    </form>
    </body>
    </html>
    sendmail.php
    PHP Code:
    <?php
    // fetching form values
    $name$_POST['name'];
    $email$_POST['email'];

    $to="youremailhere";
    $subject="Form details";
    $header="from: $name <$email>";
    $message.="Hi \r\n\n";
    $message.="Someone submitted the form, see the details below: \r\n\n";
    $message.="\n Name: $name \r";
    $message.="\n Email: $email";

    // send email
    $sendmail mail($to,$subject,$message,$header);

    if(isset(
    $sendmail))
    {
    echo 
    "Mail sent";
    }
    else
    {
    echo 
    "can't send mail";
    }

    ?>

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    First, how will giving out code to be copy/pasted help anyone learn not to copy/paste?

    Second, isset($sendmail) will always be true - you just set it to the return value of the mail() function. If mail() didn't work, then $sendmail will be FALSE, but it will still be 'set'.

  7. #7
    Join Date
    Jan 2012
    Location
    India
    Posts
    45
    Thanks
    12
    Thanked 1 Time in 1 Post

    Default

    ok bro

    then should i do this?

    PHP Code:
    if($sendmail)
    {
    echo 
    "Mail sent";
    }
    else
    {
    echo 
    "can't send mail";


  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Probably like this:
    Code:
    if($sendmail!==FALSE)
    But there might be other problems with the script. I haven't tested it.

    (Note the three comparison symbols there-- !== -- and that's necessary, including the double equals signs. It means "not exactly equal to" rather than just != which means "not roughly equivalent to" [based on differing types of variables like 0 and FALSE])
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    You could also skip assigning a variable and just check the return value of the function directly:
    PHP Code:
    if( mail$to,$subject,$message,$header ) === TRUE ){ print 'mail sent!'; }
    else{ print 
    'mail failed!'; } 
    Quote Originally Posted by djr33 View Post
    But there might be other problems with the script. I haven't tested it.
    you should also validate and/or sanitize the user input before sending it off in an email.

    Even though you aren't intentionally sending the message in HTML format, there's no way to guarantee that your mail server won't (helpfully) add that mime-type, or that the email client won't see html tags in the (user-submitted) text and (helpfully) try to parse it.
    Last edited by traq; 02-02-2012 at 05:26 PM.

  10. The Following User Says Thank You to traq For This Useful Post:

    ankush (02-03-2012)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •