Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-18-2012, 04:31 AM   PM User | #1
mbsmi
New to the CF scene

 
Join Date: Feb 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mbsmi is an unknown quantity at this point
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:
Quote:
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.
Quote:
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..
mbsmi is offline   Reply With Quote
Old 02-18-2012, 04:55 AM   PM User | #2
Microsuck
Regular Coder

 
Microsuck's Avatar
 
Join Date: Oct 2011
Location: 127.0.0.1
Posts: 123
Thanks: 44
Thanked 5 Times in 5 Posts
Microsuck is an unknown quantity at this point
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!"?>
Microsuck is offline   Reply With Quote
Old 02-18-2012, 09:17 AM   PM User | #3
scriptburn
New Coder

 
Join Date: Jul 2011
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
scriptburn is an unknown quantity at this point
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
scriptburn is offline   Reply With Quote
Old 02-18-2012, 12:49 PM   PM User | #4
mbsmi
New to the CF scene

 
Join Date: Feb 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mbsmi is an unknown quantity at this point
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.
mbsmi is offline   Reply With Quote
Old 02-18-2012, 02:19 PM   PM User | #5
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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 )
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 02-18-2012, 05:57 PM   PM User | #6
mbsmi
New to the CF scene

 
Join Date: Feb 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mbsmi is an unknown quantity at this point
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); 
mbsmi is offline   Reply With Quote
Old 02-20-2012, 11:16 AM   PM User | #7
qeemat
New to the CF scene

 
Join Date: Feb 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
qeemat is an unknown quantity at this point
Check this link for complete Email system which is validated through java script
http://www.phptoys.com/tutorial/email-validation.html
qeemat is offline   Reply With Quote
Old 02-20-2012, 11:54 AM   PM User | #8
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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.
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:52 AM.


Advertisement
Log in to turn off these ads.