0

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 :)

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ko ko
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.