Hi guys,

I'm not great with PHP and the guy I normally work with who does know a thing or too about it is on holiday.

Currently, I'm having problems using a contact form mailer which returns the following error when it is sent.

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/websitee/public_html/mailer41.php:5) in /home/websitee/public_html/mailer41.php on line 36

However, the message does end up in our email inbox so it is "functional" it just doesn't look great with a PHP error.

The code for the mailer script is,

<!--begin content section-->
<div id="content-white">
<div id="content-white-text">
<div align="center"><br><br>
<?php session_start();
if(isset($_POST['Submit'])) {   if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'mdminternet@gmail.com';
$fromsubject = 'WE';
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$subject = $_POST['subject']; 
$message = $_POST['message']; 
	$to = $youremail; 
	$mailsubject = '';
	$body = $fromsubject.',
	
A person named '.$fname.' has been browsing the website and sent through an online enquiry.

Contact them by phone on '.$lname.' or by email at '.$mail.'.

Their enquiry is as follows:

 '.$subject.'.
	
	
	 
	
	|---------END MESSAGE----------|'; 
echo "Thank you for your enquiry. You will be contacted shortly.<br/>Return to our <a href='/index.php' class='main'>Home Page</a>"; 
								mail($to, $subject, $body);
		unset($_SESSION['chapcha_code']);
   } else {
		echo 'Sorry, the security code you entered was invalid.<br/>Please go back and try again.';
   }
 } else { 
echo "Sorry, you didn't fill out the form correctly.</br>Please go back and try again."; 
}
?> 
</div>

</div>
<div id="content-white-sidebar">
<img src="images/home-side.jpg" width="330px" height="286px">
</div>
<div id="content-white-clearfix"></div>
</div>
<? include 'includes/allpage-bottom.php' ?>

I thank you in advance for your help - im convinced the problem is simple but as I said I'm just not that good with PHP.

Thanks :)

Hi, you cannot start a session with just anywhere in the page. you must declare it on every start of a page like this.

<?php  session_start(); ?>
<!--begin content section-->
<div id="content-white">
<div id="content-white-text">
<div align="center"><br><br>
<?php 
if(isset($_POST['Submit'])) { if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'mdminternet@gmail.com';
$fromsubject = 'WE';
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$subject = $_POST['subject']; 
$message = $_POST['message']; 
$to = $youremail; 
$mailsubject = '';
$body = $fromsubject.',

A person named '.$fname.' has been browsing the website and sent through an online enquiry.

Contact them by phone on '.$lname.' or by email at '.$mail.'.

Their enquiry is as follows:

'.$subject.'.




|---------END MESSAGE----------|'; 
echo "Thank you for your enquiry. You will be contacted shortly.<br/>Return to our <a href='/index.php' class='main'>Home Page</a>"; 
mail($to, $subject, $body);
unset($_SESSION['chapcha_code']);
} else {
echo 'Sorry, the security code you entered was invalid.<br/>Please go back and try again.';
}
} else { 
echo "Sorry, you didn't fill out the form correctly.</br>Please go back and try again."; 
}
?> 
</div>

</div>
<div id="content-white-sidebar">
<img src="images/home-side.jpg" width="330px" height="286px">
</div>
<div id="content-white-clearfix"></div>
</div>
<? include 'includes/allpage-bottom.php' ?>

Cheers! :D

session_start(); must start first line of the fiile.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.