...

View Full Version : PHP Mail Form Issue



mbsmi
02-18-2012, 05:31 AM
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
$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 == 0 || !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 == 0 || !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.

Microsuck
02-18-2012, 05:55 AM
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.

scriptburn
02-18-2012, 10:17 AM
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

mbsmi
02-18-2012, 01:49 PM
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.

Nightfire
02-18-2012, 03:19 PM
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 )

mbsmi
02-18-2012, 06:57 PM
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:

error_reporting(0);

qeemat
02-20-2012, 12:16 PM
Check this link for complete Email system which is validated through java script
http://www.phptoys.com/tutorial/email-validation.html

Nightfire
02-20-2012, 12:54 PM
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:

error_reporting(0);

You shouldn't hide errors. You should fix them.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum