Jump to content

Getting an error on contact form submission.


JTRLabs
Go to solution Solved by maxxd,

Recommended Posts

http://www.sustainableconnexions.org/contact/ getting an error on submission.

 

error:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/29/9279029/html/wp-content/themes/Susainable_Connexions_International/header.php:3) in/home/content/29/9279029/html/wp-content/themes/Susainable_Connexions_International/functions.php on line 134

<?php
/**
 * Migration functions and definitions.
 *
 * Sets up the theme and provides some helper functions, which are used
 * in the theme as custom template tags. Others are attached to action and
 * filter hooks in WordPress to change core functionality.
 *
 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
 * to a filter or action hook.
 *
 * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
 *
 */


/**
 * Sets up theme defaults and registers the various WordPress features that
 * the Migration theme supports.
 *
 * @uses add_editor_style() To add a Visual Editor stylesheet.
 * @uses add_theme_support() To add support for post thumbnails
 * @uses register_nav_menu() To add support for navigation menus.
 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
 *
 */
function migration_setup() {

	// This theme styles the visual editor with editor-style.css to give it some niceties.
	add_editor_style();

	// This theme uses wp_nav_menu() in one location.
	register_nav_menu( 'primary', __( 'Primary Menu', 'migration' ) );

	// This theme uses a custom image size for featured images, displayed on "standard" posts.
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 500, 9999 ); // Unlimited height, soft crop
}
add_action( 'after_setup_theme', 'migration_setup' );


/**
 * Enqueues scripts and styles for front-end.
 */
function migration_scripts_styles() {
	global $wp_styles;

	/*
	 * Loads our main stylesheet.
	 */
	wp_enqueue_style( 'migration-style', get_stylesheet_uri() );

	/*
	 * Optional: Loads the Internet Explorer specific stylesheet.
	 */
	//wp_enqueue_style( 'migration-ie', get_template_directory_uri() . '/css/ie.css', array( 'migration-style' ), '20121010' );
	//$wp_styles->add_data( 'migration-ie', 'conditional', 'lt IE 9' );
}
add_action( 'wp_enqueue_scripts', 'migration_scripts_styles' );




remove_filter ('the_content',  'wpautop');
remove_filter ('comment_text', 'wpautop');




function add_animation_slider_func( $atts ) 
{
	$result = '<div class="col-md-10 col10-size">
              <div id="main-slide" class="carousel slide" data-ride="carousel"><div class="carousel-inner">';
			  
			//  query_posts('cat=4');
			  
	$random_post = new WP_query(); 
	$random_post->query('cat=5'); 		  
			  
			  $total = 0;
			  
	while ($random_post->have_posts()) 
	{
		 
		$random_post->the_post();

		$feat_image = wp_get_attachment_url( get_post_thumbnail_id($random_post->ID) );
		
		if($total == 0) { 
			$activeClass =  'class="item active"';
		}
		else
		{
			$activeClass = 'class="item"';
		}
		
		$result .= '<div '.$activeClass.'><img class="img-responsive" src="'.$feat_image.'" alt="slider"/></div>';
		$total++;
	}
	
	$result .= '</div>
                 <div class="slider_btn">
                     	 <ol class="carousel-indicators">';
						 
	 for($i = 0; $i < $total; $i++)
	 {
		 $activeClass = "";
		if($i == 0) { 
			$activeClass =  'class="active"';			
		}
		$result .= '<li data-target="#main-slide" data-slide-to="'.$i.'" '.$activeClass.'></li>';
	 }
	
		
		$result .= ' </ol>
                      </div>
                  </div>
                               </div>
             
         </div>';
		wp_reset_postdata();
	return $result; 
	
}
add_shortcode( 'add_animation_slider', 'add_animation_slider_func' );


function add_contact_form_short_func( $atts)
{
	extract(shortcode_atts(array('val1' => ''), $atts));
$displayMessage = 'No Email Submitted';
if(isset($_POST['submit-btn']))
{
session_start();
error_reporting(0);
	$displayMessage = "Thank you for your message. We will get back to you soon.";
	if(isset($_SESSION['cap_code']) && isset($_POST["captcha"]))
	{
		$captcha = $_POST["captcha"];
		if($captcha == $_SESSION['cap_code'])
		{
			$Name = $_POST['firstName'];
			$Email = $_POST['email'];
			$Subject = $_POST['Subject'];
			$message = $_POST['txtmessage'];
			
			$to = $val1;//your adress here
			$subject = "Contact Us(Enquiry Form)";
			$host = "info@sci.jtrlabs.com";
			$message = "<b>Name: $Name<br>Email: $Email <br>Subject: $Subject<br>Message: $message<br>Thanks and regards"; //Mail content here (can be html!)
			
			$headers = "From:" . $host. "\r\n";
			$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
			
			
			mail($to, $subject, $message, $headers);
			
		}
		else
		{
			$displayMessage = "Capticha Mismatched, Email Failed";
		}
	}
	else
	{
		$displayMessage = "Capticha Not Set, Email Failed";
	}
}

return "<p>$displayMessage</p>";


}


add_shortcode( 'add_contact_form_short', 'add_contact_form_short_func' );


function add_vol_form_short_func( $atts)
{

extract(shortcode_atts(array('val2' => ''), $atts));
$displayMessage = 'No Email Submitted';
if(isset($_POST['submit-btn']))
{
session_start();
error_reporting(0);
	$displayMessage = "Thank you for your message. We will get back to you soon.";

	if(isset($_SESSION['cap_code']) && isset($_POST["captcha"]))
	{
		$captcha = $_POST["captcha"];
		if($captcha == $_SESSION['cap_code'])
		{
		$Name = $_POST['fname'];
		$StreetAddress = $_POST['StreetAddress'];
		$ZipCode = $_POST['ZipCode'];
		$HomePhone = $_POST['HomePhone'];
		$WorkPhone = $_POST['WorkPhone'];
		$Email = $_POST['inputEmail'];
		$interests = $_POST['interests'];
		
        $Other = $_POST['Other'];
		
		$interestMsg = '';
		
		foreach ($interests as $interest){
			$interestMsg .= $interest."<br />";		
		}
		
		if(!empty($Other))
		{
			$interestMsg .= $Other;
		}
        
	
		$Region = $_POST['optradio'];	
		$Qualifications = $_POST['Skills'];
		
		$Year1 = $_POST['Year1'];
		$Other1 = $_POST['Other1'];
		$Year2 = $_POST['Year2'];
		$Other2 = $_POST['Other2'];
		$Year3 = $_POST['Year3'];
		$Other3 = $_POST['Other3'];
		$Year4 = $_POST['Year4'];
		$Other4 = $_POST['Other4'];
		$Year5 = $_POST['Year5'];
		$Other5 = $_POST['Other5'];
		$Experience = $_POST['Experience'];
		
		$Length = $_POST['Length'];
		$jj = '';
		  
		 if(empty($Length)) 
		 {
		   echo("You didn't select any Classes.");
		 } 
		 else
		 {
		  	foreach ($Length as $len){
			$jj .= $len."<br />";		
		}	
		 }
	
		$Nameprinted = $_POST['FullName'];
		$Date1 = $_POST['Date1'];
	
		$to = $val2;//your adress here
		
	
	
		
		$subject = "Volunteer (Enquiry Form)";
		$host = "info@sustainableconnexions.org";
		$message = "<h3>Contact Information:</h3>
        <b>Name:</b> $Name<br>
		<b>Street Address:</b> $StreetAddress <br>
		<b>Zip Code:</b> $ZipCode<br>
		<b>HomePhone:</b> $HomePhone<br>
		<b>WorkPhone:</b> $WorkPhone <br>
		<b>Email:</b> $Email<br><br>
        
        <h3>Interests:</h3>
        $interestMsg<br/></br>
		
		<h3>Location:</h3>
        $Region<br/></br>
		
		<h3>Special Skills or Qualifications:</h3>
        $Qualifications<br/></br>
		
		<h3>Education:</h3>
        <table>
			<thead>
				<tr>
					<th style='padding: 6px;text-align: left;'>
						EducationYear
					</th>
					<th style='padding: 6px;text-align: left;'>
						CompletedOther 
					</th>
					<th style='padding: 6px;text-align: left;'>
						Certifications/Licenses
					</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td style='padding: 6px;text-align: left;'>
						High School
					</td>
					<td style='padding: 6px;text-align: left;'>
						$Year1
					</td>
					<td style='padding: 6px;text-align: left;'>
						$Other1
					</td>
				</tr>
				<tr>
					<td style='padding: 6px;text-align: left;'>
						Vocational Education
					</td>
					<td style='padding: 6px;text-align: left;'>
						$Year2
					</td>
					<td style='padding: 6px;text-align: left;'>
						$Other2
					</td>
				</tr>
				<tr>
					<td style='padding: 6px;text-align: left;'>
						Bachelor
					</td>
					<td style='padding: 6px;text-align: left;'>
						$Year3
					</td>
					<td style='padding: 6px;text-align: left;'>
						$Other3
					</td>
				</tr>
				<tr>
					<td style='padding: 6px;text-align: left;'>
						Masters
					</td>
					<td style='padding: 6px;text-align: left;'>
						$Year4
					</td>
					<td style='padding: 6px;text-align: left;'>
						$Other4
					</td>
				</tr>
				<tr>
					<td style='padding: 6px;text-align: left;'>
						Doctorate
					</td>
					<td style='padding: 6px;text-align: left;'>
						$Year5
					</td>
					<td style='padding: 6px;text-align: left;'>
						$Other5
					</td>
				</tr>
				
			</tbody>
		</table>
		<br/></br>
		
		
		<h3>Previous Volunteer Experience:</h3>
        $Experience<br/></br>
		
		<h3>Length of Time Available to Serve:</h3>
        $jj<br/></br>
		
		<h3>Agreement and Signature:</h3>
      	<b>Full Name:</b> $Nameprinted<br>
		<b>Date:</b> $Date1<br/><br/><br/>
		
        <b>Thanks and regards<br>
		$Nameprinted";
		
		$headers = "From:" . $host. "\r\n";
		//$headers .= "MIME-Version: 1.0" . "\r\n";
		$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
		
		//$additional_parameters = "-f ".$from;
		
		mail($to, $subject, $message, $headers);
		//mail($to, $subject, $message, $headers);
	
	}
	else
	{
		$displayMessage = "Capticha Mismatched, Email Failed";
	}
	
	}
	else
	{
		$displayMessage = "Capticha Not Set, Email Failed";
	}

}

return "<p>$displayMessage </p>";
}


add_shortcode( 'add_vol_form_short', 'add_vol_form_short_func' );

Edited by JTRLabs
Link to comment
Share on other sites

  • Solution

You've got output before the call to session_start(). If I'm not mistaken, WordPress replaces shortcode at the point that it encounters it in the loop content. Which means there's the header file, and processing, all the HTML, and any post content before that shortcode that's output to screen before the session_start() call. I'd recommend starting the session either using the init hook, or at the top of your functions sheet.

Link to comment
Share on other sites

In your theme directory, there should be a file called 'functions.php'. There's more than likely a line toward the top that reads something like:

defined('ABSPATH') or die('No direct access, please');

Add the session_start() line after that line and remove it from line 134 of the posted code. That should take care of the error, I'd think.

Link to comment
Share on other sites

In your theme directory, there should be a file called 'functions.php'. There's more than likely a line toward the top that reads something like:

defined('ABSPATH') or die('No direct access, please');

Add the session_start() line after that line and remove it from line 134 of the posted code. That should take care of the error, I'd think.

 

Perfect. That was the functions.php so I moved session_start to the top and was able to send the contact email with out getting that error. thank you so much.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.