473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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

Expand|Select|Wrap|Line Numbers
  1. <?
  2. //edit these lines
  3. $your_name="";
  4. $your_email="leomarogie@gmail.com";
  5. $your_web_site_name="";
  6. ?>
  7.  
  8. <?php 
  9. //If the form is submitted
  10. if(isset($_POST['name'])) {
  11.  
  12.         //Check to make sure that the name field is not empty
  13.         if(trim($_POST['name']) === '') {
  14.             $hasError = true;
  15.         } else {
  16.             $name = trim($_POST['name']);
  17.         }
  18.  
  19.         //Check to make sure sure that a valid email address is submitted
  20.         if(trim($_POST['email']) === '')  {
  21.             $hasError = true;
  22.         } else if (!trim("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
  23.             $hasError = true;
  24.             $errorMessage = "Please enter a valid email address!";
  25.         } else {
  26.             $email = trim($_POST['email']);
  27.         }
  28.  
  29.         //Check to make sure that the phone field is not empty
  30.         if(trim($_POST['phone']) === '') {
  31.             $hasError = true;
  32.         } else {
  33.             $phone = trim($_POST['phone']);
  34.         }
  35.  
  36.         //company name
  37.         $company_name = trim($_POST['company_name']);
  38.  
  39.         //company url
  40.         $company_url = trim($_POST['company_url']);
  41.  
  42.  
  43.         //Check to make sure comments were entered    
  44.         if(trim($_POST['message']) === '') {
  45.             $hasError = true;
  46.         } else {
  47.             if(function_exists('stripslashes')) {
  48.                 $comments = stripslashes(trim($_POST['message']));
  49.             } else {
  50.                 $comments = trim($_POST['message']);
  51.             }
  52.         }
  53.  
  54.         //If there is no error, send the email
  55.         if(!isset($hasError)) {
  56.  
  57.             $emailTo = $your_email;
  58.             $subject = 'Contact Form Submission from '.$name;
  59.  
  60.             //message body 
  61.             $body  ="Name: $name \n\n";
  62.             $body .="Email: $email \n\n";
  63.             $body .="Phone:$phone\n\n";
  64.             $body .="Company Name:$company_name\n\n";
  65.             $body .="Company Url:$company_url \n\n";
  66.             $body .="Message: $comments";
  67.  
  68.  
  69.             $headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
  70.  
  71.             mail($emailTo, $subject, $body, $headers);
  72.  
  73.             $emailSent = true;
  74.     }
  75.  
  76.  
  77.  
  78. ?>
  79.  
  80. <?php if(isset($emailSent) == true) { ?>
  81.     <div class="ok_box">
  82.         <h3>Thanks, <?php echo $name;?></h3>
  83.         <p>Your email was successfully sent. We will be in touch soon.</p>
  84.     </div>
  85. <?php } ?>
  86.  
  87. <?php if(isset($hasError) ) { ?>
  88.     <div class="error_box">
  89.         There was an error submitting the form.
  90.         <br />
  91.         <?php echo $errorMessage;?>
  92.     </div>
  93. <?php } ?>
Sep 13 '12 #1
1 2306
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.
Sep 22 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ginoboy | last post by:
Hello there I have a problem in executing mysql using java netbeans. all i want is to execute a batch file. this is my code: "try { ...
1
by: mohammedsk | last post by:
Hi, I am trying to save information into MySQL using PHP. The data I am saving is in Arabic language. The database table will show some "???" or other characters. If I insert the text directly...
3
by: blackevanuz | last post by:
Hi I want to storage a txt file into mysql using a blob and after that extract it, the code i use to save it is: fs = new FileStream("C:\\Documents and Settings\\Pru.txt",...
0
by: bnashenas1984 | last post by:
Hi everyone I'm a PHP programmer and I'v recently started to learn flash and AS3. Everything is going fine except that I don't know how to send data to Mysql. I tried to find scripts on google and...
4
by: ithinc | last post by:
Is there a method to send gmail through a xmlhttprequest?
3
by: emsik1001 | last post by:
Hi http://dev.mysql.com/doc/query-browser/en/mysql-query-browser-connection.html I'm trying to connect from my Windows based PC to a dedicated server which is running on Linux system. I...
0
by: manu g | last post by:
i am using xampp as a server it has apache mercury and all..even if i rum mercury still i get the error Warning: mail() : Failed to connect to mailserver at "localhost" port 25, verify your "SMTP"...
0
by: sijran | last post by:
I've changed my php.ini setting smtp-port settings to my ISP smtp but still i'm unable to send mail.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.