SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with php section of html5 contact form

    I'm having a bit of trouble getting a contact form to function correctly. The template did not come with any contact related php of js. I have managed to get it to send the email fine. But the content of the email is not being sent. If possible, I would like some help with my contact.php. Below is my code:

    HTML
    Code:
    <form action="contact.php" method="post">
    					    	<div>
    					    		<input type="text" class="textbox" value="Name (Required)" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name';}">
    						    	
    						    </div>
    						    <div>
    						    	<input type="text" class="textbox" value="Email (Required)" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email';}">
    						    </div>
    						    <div>
    						     	<input type="text" class="textbox" value="Subject" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Subject';}">
    						    </div>
    						    <div>
    						    	<textarea value="Message:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Message';}">Describe Your project in detail...</textarea>
    						    </div>
    							<label>*What is 2+2? (Anti-spam)</label>
    <input name="human" placeholder="Type Here">
    <input type="hidden" name="send" >
    						    <button class="btn btn-8 btn-8c">Submit</button>
    					    </form>
    CSS
    Code:
    .col{
    	display: block;
    	float:left;
    	margin: 1% 0 1% 1.6%;
    }
    .col:first-child{
    	margin-left:0;
    }	
    .span_2_of_3 {
    	width: 66.1%;
    }
    .span_1_of_3 {
    	width: 32.2%;
    }
    .contact-form{
    	position:relative;
    	padding-bottom:30px;
    }
    .contact-form div{
    	padding:5px 0 15px;
    }
    .contact-form input[type="text"],.contact-form textarea{
    	padding: 12px;
    	display: block;
    	width: 95%;
    	background:#017e80;
    	border: none;
    	outline: none;
    	color:#88B8B9;
    	font-size: 0.8125em;
    	font-family: 'Open Sans', sans-serif;
    	-webkit-appearance: none;
    }
    .contact-form textarea{
    	resize:none;
    	height:120px;		
    }
    .btn {
    	border: none;
    	font-size: inherit;
    	color: inherit;
    	background: none;
    	cursor: pointer;
    	padding: 20px 75px;
    	display: inline-block;
    	color:#fff;
    	text-transform: uppercase;
    	letter-spacing: 1px;
    	outline: none;
    	position: relative;
    	-webkit-transition: all 0.3s;
    	-moz-transition: all 0.3s;
    	transition: all 0.3s;
    	font-family: 'Open Sans', sans-serif;
    }
    .btn-8 {
    	display: block;
    	background: #017E80;
    	-webkit-transform-style: preserve-3d;
    	-moz-transform-style: preserve-3d;
    	transform-style: preserve-3d;
    }
    .btn-8c:hover {
    	-webkit-transform: rotateY(15deg);
    	-moz-transform: rotateY(15deg);
    	-ms-transform: rotateY(15deg);
    	transform: rotateY(15deg);
    }
    .company_address p{
    	font-family: 'Open Sans', sans-serif;
    	color:#C6D7DA;
    	font-size:0.8125em;
    	line-height: 1.8em;
    	margin-bottom: 2%;
    }
    PHP
    Code:
    <?php
    $field_name = $_POST['cf_name'];
    $field_email = $_POST['cf_email'];
    $field_message = $_POST['cf_message'];
    
    $mail_to = 'MyEmail@Host.com';
    $subject = 'Message from a site visitor '.$field_name;
    
    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Message: '.$field_message;
    
    $headers = 'From: '.$field_email."\r\n";
    $headers .= 'Reply-To: '.$field_email."\r\n";
    
    $mail_status = mail($mail_to, $subject, $body_message, $headers);
    
    if ($mail_status) { ?>
    	<script language="javascript" type="text/javascript">
    		alert('Thank you for the message. We will contact you shortly.');
    		window.location = 'temp.html';
    	</script>
    <?php
    }
    else { ?>
    	<script language="javascript" type="text/javascript">
    		alert('Message failed. Please, send an email to mymail@host.com');
    		window.location = 'temp.html';
    	</script>
    <?php
    }
    ?>

  2. #2
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    317
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Your form is missing the name attributes, so the PHP script can't find any content being sent to it.

    Try this for your html page:

    Code:
    <form action="contact.php" method="post">
    					    	<div>
    					    		<input type="text" class="textbox" name="cf_name" value="Name (Required)" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name';}">
    						    	
    						    </div>
    						    <div>
    						    	<input type="text" class="textbox" name="cf_email" value="Email (Required)" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email';}">
    						    </div>
    						    <div>
    						     	<input type="text" class="textbox" value="Subject" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Subject';}">
    						    </div>
    						    <div>
    						    	<textarea value="Message:" name="cf_message" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Message';}">Describe Your project in detail...</textarea>
    						    </div>
    							<label>*What is 2+2? (Anti-spam)</label>
    <input name="human" placeholder="Type Here">
    <input type="hidden" name="send" >
    						    <button class="btn btn-8 btn-8c">Submit</button>
    					    </form>

  3. #3
    SitePoint Member
    Join Date
    Feb 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much! Nailed it and works like a charm. I am so thankful for your help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •