Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2008
    Location
    Derby
    Posts
    4,668
    Tokens
    262

    Latest Awards:

    Default Another quick PHP question....

    Hey, Im learning a bit of PHP as youve probably gathered from my many threads on PHP, and was jsut wondering if someone could help me out with this:
    Im making an email contact us form,
    HTML Code:
    <form method="post" action="send.php"> 
    Email: <input name="email" type="text"><br>
    Message:<br> 
    <textarea name="message" rows="15" cols="40"></textarea><br> 
    <input type="submit"> 
    </form>
    Thats the very simple form i made.....
    My question is, the send.php is going to contact the PHP for what is going to be sent (obviously) And i was wondering why this wont work:

    PHP Code:
    <?php 
    $to 
    callum@thenrs.net
    $subject "Contact Us"
    $email $_REQUEST['email'] ; 
    $message $_REQUEST['message'] ;
    $sent mail($to$subject$message;) ; 
    if(
    $sent
    {print 
    "Your mail was sent successfully"; }
    else 
    {print 
    "We encountered an error sending your mail"; }
    ?>
    Thanks for any help,
    Callum,
    (I feel like such a noob asking sooo many questions)
    Back for a while

  2. #2
    Join Date
    Sep 2008
    Location
    UK
    Posts
    3,670
    Tokens
    0

    Latest Awards:

    Default

    You're not checking if the form has been posted or not, thats why it won't work.
    Back for a while.

  3. #3
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    It doesn't matter if it's checking or not, it's going to send.php through a posted form, so of course it's going to be posted, although I don't recommend this, you'll get a lot of blank e-mails.

    If it was at the top of the form's page, then yes.. it would need to be checked.

    The code here is horrible, so I'm going to rewrite it again. Basically the problem, I'm pretty sure, is that your e-mail address: to, is being written as an integer (no ""(s)).

    You really need to start using a debugger to check for errors, or turn your error reporting on at the top of your scripts:

    PHP Code:
    ini_set("display_errors""On");
    error_reporting(E_ERRORS); 
    If you check for errors, you will see that is the problem:



    Another reason, is you have a semicolon in the middle of your mail() before the closing parenthesis.

    $sent = mail($to, $subject, $message ;

    Also, why are you even getting the $email from the post and not even using it?

    Put this as your send.php file, it should work:

    PHP Code:
    <?php 
    if($_POST) {
        
    $to_email "[email protected]";         // set to e-mail.  This needs to be enclosed.
        
    $email_subject "Contact Us";         // subject for the e-mail.
        
    $email $_POST["email"];       // gets the e-mail from the post.
        
    $email_message $_POST["message"];   // gets the message from the post.
        
        /* Let me say, you probably should clean the $message variable for XSS */
        /* as your e-mail client probably will display this if it is web-based */
        
        
    $message nl2br($message);     // converts textbox linebreaks to <br>'s, other wise you have a long message, no wraps.
        
        
    $send_mail = @mail($to_email$email_subject$email_message); // send the e-mail to the user, supress the errors.
        
        /* Checks to see if the mail was sent correctly. */
        
    if($send_mail) {
            exit(
    "Your e-mail as successfully send."); // the mail was sent to the user, stop here.
        
    } else {
            exit(
    "We have encountered a problem in sending your e-mail.  Please try again later."); // the mail was not sent, problem.
        
    }
    }
    ?>

Posting Permissions

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