Jump to content

can't get session message to display


corbeeresearch

Recommended Posts

Hi,

 

I'm having a problem with contact form not display message log. It does successfully send, but fails to get the session variables. Where did I go wrong?

 

This is my contact form code

<?php
include('includes/ui.php');
head('Contact Us','contactpage.css');
?>
<script src="js/SpryValidationTextField.js" type="text/javascript"></script>
<link href="js/SpryValidationTextField.css" rel="stylesheet" type="text/css" />

<script src="js/SpryValidationTextarea.js" type="text/javascript"></script>
<link href="js/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
<div class="section">
         	<h3>Contact Us</h3>            
            <div class="scontent">
<?php
/* -------------------------------------------------
	Displays success/error message 
--------------------------------------------------*/
if ($_SESSION['message']!='') {
?>
<div id="log"><?php echo $_SESSION['message']; ?></div>
<?php unset($_SESSION['message']) ?>

<?php } ?>


<?php
/* -------------------------------------------------
	Contact Form
--------------------------------------------------*/
?>
            <p><em>If you have any questions, feel free to fill the form below:</em></p>
            <form action="sendmail.php" method="post">
            	<label>Name:</label>
<span id="sprytextfield1">
            	<input type="text" class="istext" name="name"/>
            	<span class="textfieldRequiredMsg">This field is required.</span></span>
        <label>Email:</label>
        <span id="sprytextfield2">
        <input type="text" class="istext" name="email"/>
        <span class="textfieldRequiredMsg">This field is required.</span></span>
  <label>Message</label>
  <span id="sprytextarea1">
  <textarea name="message"></textarea>
<span class="textareaRequiredMsg">This field is required.</span></span><br/>
                </span>
        <label>Enter the code:</label>
	<img src="includes/captcha.php" /><span id="sprytextfield3">
	<input class="input" type="text" name="norobot" />
	<span class="textfieldRequiredMsg">This field is required.</span></span><br/>
                
              <input type="submit" class="btn" value="Send"/><span class="tab2em"></span><input type="reset" class="btn" value="Reset"/>
            </form>
            <div id="bible">         
		</div>
            <span class="clear"></span>
            <br class="clear"/>
            </div>            
         </div>
</div>

<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
//-->
</script>


<?php footer(); ?>  

 

This is my sendmail.php

<?php

session_start();
if (md5($_POST['norobot']) == $_SESSION['randomnr2'])	{ 
	// here you  place code to be executed if the captcha test passes
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$name = filter_var($name, FILTER_SANITIZE_STRING);
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
$message = filter_var($message, FILTER_SANITIZE_STRING);

require_once('includes/class.phpmailer.php');

$mail             = new PHPMailer();

$body             = "Someone with the ".$name." and an email address of ".$email." send you the ff message: ".$message;

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.example.com"; // SMTP server
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.example.com"; // sets the SMTP server
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "example@example.com"; // SMTP account username
$mail->Password   = "thepassword";        // SMTP account password

$mail->SetFrom('example@example.com', 'Me');

$mail->Subject    = "Message sent from site contact form";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "tosomeone@yahoo.com";
$mail->AddAddress($address, "Richard");


if(!$mail->Send()) 
{
  $_SESSION['message'] = "Failed sending, please try again later";	  
} else 
{
  $_SESSION['message'] = "Message sent";
}
}	
else 
{  
	// here you  place code to be executed if the captcha test fails	
	$_SESSION['message'] = "Invalid code";
}
header('Location: http://example.com');

?>

 

Thanks in advance

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.