Get 500 error when submit form

Discussion in 'PHP' started by pierrick419, Aug 18, 2010.

  1. #1
    Hi,

    I have a form on this page - http://www.organicspirit.co.uk/contact.php using the script called "send_contact.php" when submitted.

    It used to work but now when you hit submit, you get following message -
    500 - Internal server error.
    There is a problem with the resource you are looking for, and it cannot be displayed.


    Do I need to understand that the issue lies with the hosting provider or is there something wrong with my script (which I pasted below)

    send_contact.php ---------------------------------------

    <?php
    // Contact subject
    $subject = $_POST['subject'];
    // Details
    $message = $_POST['detail'];
    // Mail of sender
    $mail_from = $_POST['customer_mail'];
    // From
    $header = "from: $name <$mail_from>";
    // Enter your email address
    $to = 'info@organicspirit.co.uk';
    $send_contact = mail($to,$subject,$message,$header);
    // Check, if message sent to your email

    header ('Location: http://www.organicspirit.co.uk/thank-you.html');
    exit ();

    if($send_contact){
    echo "We've received your contact information";
    }
    else {
    echo "ERROR";
    }
    ?>

    Thank you for your help!

    P
     
    pierrick419, Aug 18, 2010 IP
  2. Narrator

    Narrator Active Member

    Messages:
    392
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    80
    #2
    What does the server log say? Is the email still being sent?
    $name is null but that shouldn't be the problem. Headers should end with a newline and are case sensitive so try using
    $header = "From: $name <$mail_from> \r\n";
    PHP:
    Some hosting companies require using the -f parameter so if that doesn't work try
    $send_contact = mail($to,$subject,$message,$header,'-finfo@organicspirit.co.uk');
    PHP:
    Hope that helps,
    Cheers!
     
    Narrator, Aug 18, 2010 IP
  3. vinoth.t

    vinoth.t Peon

    Messages:
    156
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think you may get error like

    Warning: Cannot modify header information - headers already sent by (output started at D:\Program Files\xampp\htdocs\test\head.php:12) in D:\Program Files\xampp\htdocs\test\head.php on line 15


    The reason is you have already set the header to redirect the page using "header(location:...)" after setting this you are trying to do echo. Just commend the echo statement it will work
     
    vinoth.t, Aug 19, 2010 IP
  4. pierrick419

    pierrick419 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks Narrator. I tried what you suggested but still got the error :(
     
    pierrick419, Aug 19, 2010 IP
  5. pierrick419

    pierrick419 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks vinoth.t. I am not sure what you mean (because I am useless at php) by commend the echo statement I am afraid. Do you mean 'command' or 'comment'? And could you maybe paste how the script should read? Thanks again!
     
    pierrick419, Aug 19, 2010 IP
  6. vinoth.t

    vinoth.t Peon

    Messages:
    156
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Just skip the echo statement..
     
    vinoth.t, Aug 19, 2010 IP
  7. pierrick419

    pierrick419 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks vinoth.t.

    I tried two options but still got the 500 error. Here below is what I tried -

    <?php
    // Contact subject
    $subject = $_POST['subject'];
    // Details
    $message = $_POST['detail'];
    // Mail of sender
    $mail_from = $_POST['customer_mail'];
    // From
    $header = "from: $name <$mail_from>";
    // Enter your email address
    $to = 'pierrick419@hotmail.com';
    $send_contact = mail($to,$subject,$message,$header);
    // Check, if message sent to your email

    if($send_contact){
    echo "We've received your contact information";
    }
    else {
    echo "ERROR";
    }
    ?>


    ----------------------------------------------------


    <?php
    // Contact subject
    $subject = $_POST['subject'];
    // Details
    $message = $_POST['detail'];
    // Mail of sender
    $mail_from = $_POST['customer_mail'];
    // From
    $header = "from: $name <$mail_from>";
    // Enter your email address
    $to = 'info@organicspirit.co.uk';
    $send_contact = mail($to,$subject,$message,$header);
    // Check, if message sent to your email

    header ('Location: http://www.organicspirit.co.uk/thank-you.html');
    exit ();

    else {
    echo "ERROR";
    }
    ?>

    Help! :)

    P
     
    pierrick419, Aug 19, 2010 IP
  8. uabclst

    uabclst Greenhorn

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    You could check that there's no hidden space or white space before the first <?php in the file.
    A php file must start with <?php

    Then I think vinoth meant to try with the end of the script looking like this:

    if($send_contact){
    //echo "We've received your contact information";
    }
    else {
    //echo "ERROR";
    }
    ?>
     
    uabclst, Aug 22, 2010 IP
  9. Mindraven

    Mindraven Peon

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    The second one definitely won't work, since it has an else statement without an if.

    But you stated in your original post that it used to work but now doesn't. If it just stopped working and you didn't make any changes, then possibly the host has made some changes to the server so you might check with them.
     
    Mindraven, Aug 22, 2010 IP