contact form refuses to work, can anyone help?

Discussion in 'PHP' started by sambkk, Sep 17, 2006.

  1. #1
    Hi I want to make a contact form but I am having some trouble.

    I always use the same code for a simple form, but on a new site with a new host, it doesnt work.

    I have no idea why. I turn CGI on already.

    here is the code.

    PHP file:

    <?

    $to = "xxx@xxxx.com";

    $subject = "Email from website contact form";

    $boundary = uniqid("");

    $headers = "From: $from";

    $body = "

    Name :$user

    Email :$emailaddress

    Comment :$comments

    ";

    if (mail($to, $subject, $body,$headers)) {

    print( "Thank you for emailing us.Your file has been sent succesfully");

    ?>

    <meta http-equiv=refresh content="1;URL=http://www.peacefulseasangha.com/sampleforliz/files/CUT H.html">

    <?

    }

    else {

    print( "Error: Unknown error ocurred. The message could not be sent. Please try again later.\n");

    }

    ?>

    and here is the code from the html file:

    "...

    Contact FORM

    </div>

    <div id="cu">

    Please use the form below to send us email. Thank You.

    <div id="flabels">

    <br>Name:

    <br>Email:

    <br>Comments:

    </div>

    <div id="fitems">

    <br>

    <form name="form1" method="post" action="mail_t.php">

    <input type="text" name="user" size="25">

    <input type="text" name="emailaddress" size="25">

    <textarea cols="10" rows="4" name="comments"></textarea>

    <input type="submit" value="Send">

    </form>

    </div> ..."

    I use the exact same code on many sites but this new site it just doesnt work with it. Does anyone have any idea what could be the reason?
    Trying to send to an email address on the domain.
    I receive no email, no error msg, nothing.

    Thanks.

    Sami
     
    sambkk, Sep 17, 2006 IP
  2. VONRAT

    VONRAT Banned

    Messages:
    181
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    VONRAT, Sep 18, 2006 IP
  3. ThomasNederman

    ThomasNederman Peon

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think there can be a easy solution. If you type $_POST['from'] and not $from i think it can work better. This feature of using $from is disabled in later versions of php due to security(this is on all fields in the form $_POST['subject'] etc)
     
    ThomasNederman, Sep 18, 2006 IP
  4. sambkk

    sambkk Guest

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi
    thanks for the comments.
    I have been actually advised to do that before but didnt know how to, your explanation looks like I can understand , thanks I'll give it a try.

    Sami
     
    sambkk, Sep 18, 2006 IP
  5. sambkk

    sambkk Guest

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi
    this is embarassing,I still didnt get it despite good advice
    this is what my code looks like now:

    <?
        $to = $_POST['xxxx@xxxxx.com'];
        $subject = $_POST['Email from website contact form'];
        $boundary = uniqid("");
        $headers =  $_POST['from'];
    $body =  "
    Name                   :$_POST['user']
    Email                  :$_POST[['emailaddress']
    Comment                :$_POST['comments']
    ";
    
        if (mail($to, $subject, $body,$headers)) {
            print( "Thank you for emailing us.Your file has been sent succesfully");
    ?>
         <meta http-equiv=refresh content="1;URL=http://www.peacefulseasangha.com/files/CUTH.html">
    <?
        }
         else {
            print( "Error: Unknown error ocurred. The message could not be sent. Please try again later.\n");
        }
    
    ?> 
    PHP:

    sami
     
    sambkk, Sep 18, 2006 IP
  6. discoverclips

    discoverclips Peon

    Messages:
    491
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php
    $email = $_POST['email'];
    $message = $_POST['message'];
    
    if ($email != "") {
    if (mail($email, 'test', $message)) echo "Message sent";
    else die("Could not send message");
    }
    else { ?><form method="post" action="mail.php">
    <input type="text" name="email">
    <textarea cols="30" rows="4" name="message"></textarea>
    <br /><input type="submit" value="Send" name="Send"></form>
    <?php } ?>
    Code (markup):
     
    discoverclips, Sep 18, 2006 IP