Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Mail Form Issue

    I am having an issue when I click submit on my html/php form. When I click submit (with nothing filled in), I get:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/05/6544605/html/w2/mailform.php:2) in /home/content/05/6544605/html/w2/mailform.php on line 33
    Sorry, you failed the CAPTCHA. Note that the CAPTCHA is case-sensitive. Please hit your browser back button and try again.
    I understand the last part, but the first part is what I don't get. Below is the code, with a comment at line 33.

    If I fill in the form, it goes back to my index.php page, but it shows the line below.
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/05/6544605/html/w2/mailform.php:2) in /home/content/05/6544605/html/w2/mailform.php on line 33
    
    Here is my mailform.php file below, with a comment at line 33.

    PHP Code:
    <?php 
    $dontsendemail 
    0;
    $possiblespam FALSE;
    $strlenmessage "";
    $email $_REQUEST['email']; 
    $message_start $_REQUEST['message']; 
    $message_start2 $_REQUEST['fname'];
    $message "From: $message_start2 \n Message: $message_start";


        
    $subject = array(); 
        
    $subject[1] = "General";
            
    $subject[2] = "Project";
            
    $subject[3] = "Website";
            
    $subjectindex $_REQUEST['subject'];
        if (
    $subjectindex == || !isset($_REQUEST['subject'])) die ("You did not choose a subject line. Please hit your browser back button and try again.");
        else 
    $subject $subject[$subjectindex];
        
        
    $emailaddress = array(); /* NOTE: Although your email addresses
        are visible here in this code, the person contacting you will never see these email addresses. 
        Your email addresses will remain on your server, and they will not be sent from your server 
        to the person contacting you. They will also remain invisible to spam bots. Your email addresses
        are also never stored on any of our servers. You can choose to delete or not delete this note
        when you publish this page. It will not change the functionality of the contact form. 
        */
        
    $emailaddress[1] = "michael@rroutpost1.org";
            
    $emailaddress[2] = "michael@accessdrive.net";
            
    $contactnameindex $_REQUEST['emailaddress'];
        if (
    $contactnameindex == || !isset($_REQUEST['emailaddress'])) die ("You did not choose a recipient. Please hit your browser back button and try again.");
        else 
    $emailaddress $emailaddress[$contactnameindex];
        function 
    checkcaptcha() {
            <!-- 
    Line 33 -->    session_start();
                if (
    $_SESSION["pass"] != $_POST["userpass"]) {
                    die(
    "Sorry, you failed the CAPTCHA. Note that the CAPTCHA is case-sensitive. Please hit your browser back button and try again.");
                    return 
    1;
                }
            }
        
    function 
    checkemail($field) {
        
    // checks proper syntax
        
    if( !preg_match"/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/"$field))
        {
            die(
    "Improper email address detected. Please hit your browser back button and try again."); 
            return 
    1;
        }
    }
    function 
    spamcheck($field) {
        if(
    eregi("to:",$field) || eregi("cc:",$field) || eregi("\r",$field) || eregi("\n",$field) || eregi("%0A",$field)){ 
            
    $possiblespam TRUE;
        }else 
    $possiblespam FALSE;
        if (
    $possiblespam) {
            die(
    "Possible spam attempt detected. If this is not the case, please edit the content of the contact form and try again.");
            return 
    1;
        }
    }
    function 
    strlencheck($field,$minlength,$whichfieldresponse) {
        if (
    strlen($field) < $minlength){
            die(
    $whichfieldresponse); 
            return 
    1;
        }
    }

            if (
    $dontsendemail == 0$dontsendemail checkcaptcha($email);
        
    if (
    $dontsendemail == 0$dontsendemail checkemail($email);
    if (
    $dontsendemail == 0$dontsendemail spamcheck($email);
    if (
    $dontsendemail == 0$dontsendemail spamcheck($subject);
    if (
    $dontsendemail == 0$dontsendemail strlencheck($email,10,"The email address field is too short. Please hit your browser back button and check your entry.<br />");

    if (
    $dontsendemail == 0$dontsendemail strlencheck($subject,1,"You did not choose a subject. Please hit your browser back button and check your entry.<br />");

    if (
    $dontsendemail == 0$dontsendemail strlencheck($message,10,"The message field is too short. Please hit your browser back button and check your entry.<br />");
    if (
    $dontsendemail == 0$dontsendemail strlencheck($emailaddress,8,"You have not selected a recipient of your message. Please hit your browser back button and check your entry.<br />");
    if (
    $dontsendemail == 0) {mail($emailaddress,"Subject: $subject",$message,"From: $email" ); include "index.php";}
    ?>
    Any help would be greatly appreciated.
    Last edited by mbsmi; 02-18-2012 at 04:35 AM.

  • #2
    Regular Coder Microsuck's Avatar
    Join Date
    Oct 2011
    Location
    127.0.0.1
    Posts
    123
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Try putting session_start() at the top of your script. You have to make sure nothing is sent to the browser before the session is started.
    PHP Code:
    <?php echo "Microsuck says hi!"?>

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post
    yeah try to put in the top session_start() and also check the file script with Vim or other text processors so no weird chars will be showing after <?php

  • #4
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried to move the line 33 to the top, but I still get the same error. Except it says live 2 instead of 33.

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You must have something outputting to the browser. Check for any whitespace outside of the <?php tag. The session_start() function should be the first line of your script (underneath <?php )

  • #6
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Nightfire View Post
    You must have something outputting to the browser. Check for any whitespace outside of the <?php tag. The session_start() function should be the first line of your script (underneath <?php )
    This is what I did with no luck. Something I did though was put the script at the top to turn off warnings for that script. Everything seems to work fine, is there anything that I should know about doing my script in that way?

    The script I used was:
    PHP Code:
    error_reporting(0); 

  • #7
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Check this link for complete Email system which is validated through java script
    http://www.phptoys.com/tutorial/email-validation.html

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Quote Originally Posted by mbsmi View Post
    This is what I did with no luck. Something I did though was put the script at the top to turn off warnings for that script. Everything seems to work fine, is there anything that I should know about doing my script in that way?

    The script I used was:
    PHP Code:
    error_reporting(0); 
    You shouldn't hide errors. You should fix them.


  •  

    Posting Permissions

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