Jump to content

Mail Script


Smee

Recommended Posts

Hi all,

 

As you will tell by this pretty simple example of php and the question i'm about to ask, im new to all this so any help would be good!

 

Bascically i have used a pre-written script from a book i have and currently trying to get the layout of the echo errors in a location under the form submit box for each of the first name, last name etc

 

Currently the code works and gives error replys but when trying i either stop it from working or the errors still display at the bottom of the page. Another problem is that if there are any errors made then the script does not show my Div's (footer) at the bottom of the page. I know its a problem with placement of PHP. If anyone can give me some tips i'd be very grateful.

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Red Rush Designs</title>
<link href="CSS/main.css" rel="stylesheet" type="text/css" />
<link type="text/css" media="screen" rel="stylesheet" href="CSS/colorbox.css" />
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
	<script type="text/javascript" src="colorbox/jquery.colorbox.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			//Examples of how to assign the ColorBox event to elements
			$("a[rel='example1']").colorbox();
			$("a[rel='example2']").colorbox({transition:"fade"});
			$("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
			$("a[rel='example4']").colorbox({slideshow:true});
			$(".example5").colorbox();
			$(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});
			$(".example7").colorbox({width:"80%", height:"80%", iframe:true});
			$(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"});
			$(".example9").colorbox({
				onOpen:function(){ alert('onOpen: colorbox is about to open'); },
				onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
				onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
				onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
				onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
			});

			//Example of preserving a JavaScript event for inline calls.
			$("#click").click(function(){ 
				$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
				return false;
			});
		});
	</script>
</head>

<body>

<div id="holder">

<div id="logo">

    <object width="970" height="90">
	<param name="movie1" value="loadertest2.swf" wmode="transparent">
	<embed src="images/loadertest2.swf" width="900" height="90" wmode="transparent">
	</embed>
	</object>

</div>
    
    <div id="navigation">
    
        <table id="navigation" width="970" height="53" border="0" cellpadding="0" cellspacing="0">
	<td>
        <img src="images/one.png" border="0" width="42" height="53" /></img></td>
        <td>
	<a href="index.html"><img src="images/home.png" border="0" width="59" height="53" onmouseover="this.src='images/homeon.png'" onmouseout="this.src='images/home.png'" alt="Red Rush Home" title="Red Rush Home"></a></td>
	<td>
	<img src="images/three.png" border="0" width="43" height="53" ></td>
	<td>
	<a href="aboutme.html"><img src="images/aboutme.png" border="0" width="123" height="53" onmouseover="this.src='images/aboutmeon.png'" onmouseout="this.src='images/aboutme.png'" alt="About Christopher Rushton" title="About Christopher Rushton"></a></td>
	<td>
	<img src="images/five.png" border="0" width="38" height="53" ></td>
	<td>
	<a href="designportfolio.html"><img src="images/designportfolio.png" border="0" width="240" height="53" onmouseover="this.src='images/designportfolioon.png'" onmouseout="this.src='images/designportfolio.png'" alt="Design Portfolio" title="Design Portfolio"></a></td>
        <td>
	<img src="images/seven.png" border="0" width="53" height="53" ></td>
	<td>
        <a href="contact.html"><img src="images/contact.png" border="0" width="105" height="53" onmouseover="this.src='images/contacton.png'" onmouseout="this.src='images/contact.png'" alt="Contact Red Rush" title="Contact Red Rush"></a></td>
        <td>               
	<img src="images/nine.png" border="0" width="267" height="53"></td>
            
	<td rowspan="9">
	</table>
    
    </div>
    
    <div id="content">
    
    	<div id="myphoto">
        
        <img src="images/myphoto.png" border="0" usemap="#Christopher Rushton"  />
        <map name="Christopher Rushton" id="Christopher Rushton">
          <area shape="rect" coords="17,154,91,170" href="http://www.facebook.com/people/Chris-Rushton/507874930?ref=search" target="_blank" />
        </map>
        </div>
        
        <h1> Contact redrush
        
        <br />
	<p>
<?php
if(isset($_POST['email'])) {

$email_to = "admin@footballtrip.net";
$email_subject = "redrush - Contact Form";

function died($error) {
	echo "<p>There were error(s) found with the form your submitted.</p>";
	echo "<p>These errors appear below.<br /><br /></p>";
	echo $error."<p></p>";
	die();
}

if(!isset($_POST['first_name']) ||
	!isset($_POST['last_name']) ||
	!isset($_POST['email']) ||
	!isset($_POST['telephone']) ||
	!isset($_POST['comments'])) {
	died('We are sorry, but there appears to be a problem with the form your submitted.');		
}

$first_name = $_POST['first_name']; 
$last_name = $_POST['last_name']; 
$email_from = $_POST['email']; 
$telephone = $_POST['telephone']; 
$comments = $_POST['comments']; 

$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";

?>
    
    <form name="contact" method="post" action="send_form_email.php">
<table width="500px">
</tr>
<tr>
<td valign="top">
  <label for="first_name">First Name <font color="#FF0000">*</font></label>
</td>
<td valign="top">
  <p class="submit"><input  type="text" name="first_name" maxlength="50" size="30"> 
</td>
</tr>
    
    <?

$string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$first_name)) {
  	$error_message .= '<p>The First Name you entered does not appear to be valid.<br /></p>';
  }
  	?>
    
    </p>
<tr>
<td valign="top">
  <label for="last_name">Last Name <font color="#FF0000">*</font></label>
</td>
<td valign="top">
  <p class="submit"><input  type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>    
    <p>
    
    <?

  if(!eregi($string_exp,$last_name)) {
  	$error_message .= '<p>The Last Name you entered does not appear to be valid.<br /></p>';
  }
  
  	?>
    
    </p>
<tr>
<td valign="top">
  <label for="email">Email Address <font color="#FF0000">*</font></label>
</td>
<td valign="top">
  <p class="submit"><input  type="text" name="email" maxlength="80" size="30">
</td>
</tr>
	<p>
    
    <?    
  
  if(!eregi($email_exp,$email_from)) {
  	$error_message .= '<p>The Email Address you entered does not appear to be valid.<br /></p>';
  }
  
  	?>
    
    </p>
<tr>
<td valign="top">
  <label for="telephone">Telephone Number <font color="#FF0000">*</font></label>
</td>
<td valign="top">
  <p class="submit"><input  type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<p>
    
    <?

$string_exp = "^[0-9 .-]+$";
  if(!eregi($string_exp,$telephone)) {
  	$error_message .= '<p>The Telphone Number you entered does not appear to be valid.<br /></p>';
  }
  
  	?>
    
    </p>
<tr>
<td valign="top">
  <label for="comments">Comments <font color="#FF0000">*</font></label>
</td>
<td valign="top">
  <textarea  name="comments" id="styled" maxlength="250" cols="10" rows="6"></textarea>
</td>
</tr>
    <p>
    
    <?

    if(strlen($comments) < 2) {
  	$error_message .= '<p>The Comments you entered do not appear to be valid.<br /></p>';
  }

?>
    
    </p>
   
<tr>
<td colspan="2" style="text-align:center">
  <input type="image" name="submit" id="submit" src="images/submit.png">
  <script type="text/javascript" charset="utf-8">
    $(document).ready(function(){
        $('#submit').hover(
            function(){
                $(this).attr({ src : 'images/submiton.png'});
            },
            function(){
                $(this).attr({ src : 'images/submit.png'});             }
        );
    });
  </script>

</td>
</tr>
</table>
</form>

<?    

  if(strlen($error_message) > 0) {
  	died($error_message);
  }
$email_message = "Form details below.\n\n";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";


$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<br />
<br />

<p> Thank you for contacting redrush. </p>
</h1>

<?
}
?>

</div>
    
    <div id="bottomblacklines">
    </div>

</div>

<div id="footer">
</div>

</body>
</html>


Link to comment
Share on other sites

Just a hint, which may or may not be of use.

 

When there is an if () { } statement, anything between the braces goes unprocessed if the condition is false, so for example if a function is declared in the braces it may or may not be available, or html code between the braces, it may be left out.

Link to comment
Share on other sites

Thanks for the help,

 

To make it a bit clearer when ever an error with the form is returned (Invalid First Name) it does not show the bottom two divs of my web site. The only way i can seem to resolve this is by deleting the die:() from this section.

 


function died($error) {
	echo "<h1><p>There were error(s) found with the form your submitted.</p></h1>";
	echo "<h1><p>These errors appear below.<br /><br /></p></h1>";
	echo $error."<p></p>";
	die();
}

 

But if i do this then it shows my confirmation html text that is just above the bottom two divs of my website.

 


<h1>
<p> Thank you for contacting redrush. </p>
</h1>

<?php
}
?>

 

 

Thanks again this is driving me insane :P

 

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.