Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have used this code snippet a gazillion times for contact forms but for some reason now it just doesn't send and instead it gives me the unssuccessful message I hardcoded in it.

Can you guys take a look at it

My form

PHP
<form action="bin/sendquote.php" class="contactForm" id="quote-form" name="quote-form" method="post" enctype="multipart/form-data">				
       <fieldset>
		<h4 class="semi">Personal Information</h4>
		<input type="text" class="input" id="full_name" name="full_name" placeholder="Name *" />
		<input type="text" class="input" id="email" name="email" placeholder="Email *" />
		<input type="text" class="input" id="telephone" name="telephone" placeholder="Phone *" />
		<input type="text" class="input" id="company" name="company" placeholder="Company Name *" />
		<input type="text" class="input" id="industry" name="industry" placeholder="Industry *" />				
		<input type="text" class="input" id="website" name="website" placeholder="Website " />
	</fieldset>
	<fieldset>
		<div style="width: 303px; margin-removed10px; float:left; margin-removed 35px;">
			<p class="quote_section_title">Web Design *Select One</p>							
	  	        <select id="web-design" name="web-design">
	  		        <option>Select</option>
	  			<option>CMS Website</option>
	  			<option>Marketing Website</option>
	  			<option>e-Commerce Website</option>
				<option>Landing Page</option>
	  		</select>
		</div>
		<div style="width: 303px; margin-removed10px; float: left;">
			<p class="quote_section_title">Web Marketing *Select All That Apply</p>		
			<input type="checkbox" class="input" name="web_marketing" value="onsite-seo"/><label>Onsite SEO</label><br /><br />
			<input type="checkbox" class="input" name="web_marketing" value="offsite-seo"/><label>Offsite SEO</label><br /><br />
	        	<input type="checkbox" class="input" name="web_marketing" value="blogging"/><label>Blogging</label><br /><br />
			<input type="checkbox" class="input" name="web_marketing" value="adwords"/><label>AdWords</label><br /><br />
			<input type="checkbox" class="input" name="web_marketing" value="social"/><label>Social Marketing</label><br /><br />
		</div>					
		<div style="width: 303px; margin-removed10px; float: left;">
			<p class="quote_section_title">Graphic Design *Select All That Apply</p>	
		        <input type="checkbox" class="input" name="graphic_design" value="logos"/><label>Custom Logo</label><br /><br />
			<input type="checkbox" class="input" name="graphic_design" value="signs"/><label>Signs & Banners</label><br /><br />
			<input type="checkbox" class="input" name="graphic_design" value="web promo"/><label>Web Promotions</label><br /><br />
			<input type="checkbox" class="input" name="graphic_design" value="motion graphics"/><label>Motion Graphics</label><br /><br />
		</div>
		<div style="margin-removed 20px;" class="clear"></div>
	</fieldset>
	<fieldset>					
		<p class="quote_section_title">Project Description Describe your project's main use and objective. Any specific functionality your project will do for you. (i.e. take appointements, list sales or rentals, etc) </p>	
		<textarea name="purpose" id="purpose" rows="10" cols="100" placeholder="Be as descriptive as possible here... " ></textarea>
					
		<p class="quote_section_title">Domains List all domains you own starting with the one that will be used. Or list several options	of domains you would like</p>	
		<textarea name="domain" id="domain" rows="10" cols="100" placeholder="One domain per line " ></textarea>
					
		<p class="quote_section_title">Inspirational Websites List here other websites that you think could serve as inspiration for yours. Specially those that may have a function you described above</p>	
		<textarea name="inspiration" id="inspiration" rows="10" cols="100" placeholder="One domain per line " ></textarea>
					
		<p class="quote_section_title">Date Due By</p>
		<input type="date" class="input" id="date_due" name="date_due" />
		<div style="margin-removed 20px;" class="clear"></div>
			<p class="quote_section_title">Logos and other Images</p>
			<input type="file" class="input" id="file1" name="file1" />
			<input type="file" class="input" id="file2" name="file2" />
			<input type="file" class="input" id="file3" name="file3" />
	</fieldset>
	<div class="submit"> <a class="button color"  önclick="document.getElementById('quote-form').submit()"><span>Send</span></a> </div>
        <div class="submit"> <a class="button color"  önclick="document.getElementById('quote-form').reset()" ><span>Clear</span></a> </div>
	<div class="clear"></div>
</form>



And here's the sendquote.php file that is processing the email. This is just an expanded version of email.php which it's pretty common everywhere in the internet.

PHP
<?php
if(isset($_POST['email'])) {
    
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "email@email.com";
    $email_subject = "Your email subject line";

     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['full_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['company']) ||
	  !isset($_POST['industry']) ||
        !isset($_POST['website']) ||
        !isset($_POST['web-design']) || 
	  !isset($_POST['web_marketing']) ||
        !isset($_POST['graphic_design']) ||
        !isset($_POST['purpose']) ||
	  !isset($_POST['domain']) ||
        !isset($_POST['inspiration']) ||
        !isset($_POST['date']) ||
	  !isset($_POST['file1']) ||
        !isset($_POST['file2']) ||
        !isset($_POST['file3'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }
    
    $full_name = $_POST['full_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // required
    $company = $_POST['company']; // required
    $industry = $_POST['industry']; // required
    $website = $_POST['website']; // not required
    $web_design = $_POST['web-design']; // not required
    $web_marketing = $_POST['web_marketing']; // not required
    $graphic_design = $_POST['graphic_design']; // not required
    $purpose = $_POST['purpose']; // not required
    $domain = $_POST['domain']; // not required
    $inspiration = $_POST['inspiration']; // not required
    $date = $_POST['date']; // not required
    $file1 = $_FILES['file1']['file1']; // not required
    $file2 = $_FILES['file2']['file2']; // not required
    $file3 = $_FILES['file3']['file3']; // not required
      
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  } 
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$full_name)) {
    $error_message .= 'Invalid Entry. Try Again Please.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  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 .= "Full Name: ".clean_string($full_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Company: ".clean_string($company)."\n"; 
    $email_message .= "Industry: ".clean_string($industry)."\n";
    $email_message .= "Website: ".clean_string($website)."\n";
    $email_message .= "Web design project requested: ".clean_string($web_design)."\n";
    $email_message .= "Web marketing project requested: ".clean_string($web_marketing)."\n";
    $email_message .= "Graphic design project requested: ".clean_string($graphic_design)."\n";
    $email_message .= "Purpose for Project: ".clean_string($purpose)."\n"; 
    $email_message .= "Domains desired: ".clean_string($domain)."\n"; 
    $email_message .= "Websites of Inspiration: ".clean_string($inspiration)."\n";  
    $email_message .= "Due by: ".clean_string($date)."\n";  
    $email_message .= "File 1: ".clean_string($file1)."\n"; 
    $email_message .= "File 2: ".clean_string($file2)."\n";
    $email_message .= "File 3: ".clean_string($file3)."\n"; 
        
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
header('location: /index.php'); 
die();
?>
 
<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.
 
<?php
}
?>


<!-----------------------------------------------      ------------------------------------>


I know there are other scripts out there i.e. MailHandler.PHP and forms.js...but I would much rather make this one work instead. I know this script is fine, once the bug is found


thanks
Posted
Comments
Please debug and see what is the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900