how to send gmail and save in mysql using xampp in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leomar
    New Member
    • Sep 2012
    • 1

    how to send gmail and save in mysql using xampp in php

    #using the code how can i save the data in mysql and send the data.???#

    Code:
    <?
    //edit these lines
    $your_name="";
    $your_email="leomarogie@gmail.com";
    $your_web_site_name="";
    ?>
    
    <?php 
    //If the form is submitted
    if(isset($_POST['name'])) {
    
    		//Check to make sure that the name field is not empty
    		if(trim($_POST['name']) === '') {
    			$hasError = true;
    		} else {
    			$name = trim($_POST['name']);
    		}
    		
    		//Check to make sure sure that a valid email address is submitted
    		if(trim($_POST['email']) === '')  {
    			$hasError = true;
    		} else if (!trim("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
    			$hasError = true;
    			$errorMessage = "Please enter a valid email address!";
    		} else {
    			$email = trim($_POST['email']);
    		}
    
    		//Check to make sure that the phone field is not empty
    		if(trim($_POST['phone']) === '') {
    			$hasError = true;
    		} else {
    			$phone = trim($_POST['phone']);
    		}
    
    		//company name
    		$company_name = trim($_POST['company_name']);
    
    		//company url
    		$company_url = trim($_POST['company_url']);
    
    			
    		//Check to make sure comments were entered	
    		if(trim($_POST['message']) === '') {
    			$hasError = true;
    		} else {
    			if(function_exists('stripslashes')) {
    				$comments = stripslashes(trim($_POST['message']));
    			} else {
    				$comments = trim($_POST['message']);
    			}
    		}
    		
    		//If there is no error, send the email
    		if(!isset($hasError)) {
    
    			$emailTo = $your_email;
    			$subject = 'Contact Form Submission from '.$name;
    			
    			//message body 
    			$body  ="Name: $name \n\n";
    			$body .="Email: $email \n\n";
    			$body .="Phone:$phone\n\n";
    			$body .="Company Name:$company_name\n\n";
    			$body .="Company Url:$company_url \n\n";
    			$body .="Message: $comments";
    
    
    			$headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
    			
    			mail($emailTo, $subject, $body, $headers);
    
    			$emailSent = true;
    	}
    } 
    
    
    		
    ?>
    
    <?php if(isset($emailSent) == true) { ?>
    	<div class="ok_box">
    		<h3>Thanks, <?php echo $name;?></h3>
    		<p>Your email was successfully sent. We will be in touch soon.</p>
    	</div>
    <?php } ?>
    
    <?php if(isset($hasError) ) { ?>
    	<div class="error_box">
    		There was an error submitting the form.
    		<br />
    		<?php echo $errorMessage;?>
    	</div>
    <?php } ?>
    Last edited by zmbd; Sep 13 '12, 01:07 PM. Reason: Placed required code tags. Please Use the <code/> button in the formating bar. Thnx
  • jdstankosky
    New Member
    • Sep 2012
    • 30

    #2
    This is actually pretty simple. First thing you need is a database. Create a table for this email form, and make sure it has a column for each field you want to store information for.

    You can then just execute a query to insert all your information into the table as a new row.

    In addition to the information you want to store, I would include 2 other columns, an id column (populate with uuid() ) and a date_time column (populate with now() ) to keep track of all the emails you store.

    Comment

    Working...