PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 5th, 2013, 11:54 AM
sandipcd sandipcd is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 sandipcd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 35 sec
Reputation Power: 0
How to send mysql data to email after submitting the form?

After customer filling the form, the form data will be send to mysql, and an email will sent to me with the last form data that customer submitted. All is working, but only the problem is in the email "last mysql data" is not going as inline text. So, how to do this? I am doing in PHP. In am new in PHP. Please help me.
Sample code is given below.

Please see full code (Copy and paste this URL in the Browser) - halmiratea.com/to-stackoverflow.com-not-personal1.php#problem

Code:
$mail->Subject    = "Halmira 469";
$body                = 'Print the data';
mysql_connect("localhost","XXXXXXX","XXXXXXX");
@mysql_select_db("sandi565_form11");
$query["SELECT * FROM demo ORDER BY ID DESC LIMIT 1"];
$result = mysql_query($query);
$mail->MsgHTML($body);
  $address = "XXXXXXX@gmail.com";
  $mail->AddAddress($address, "user2");

Reply With Quote
  #2  
Old January 5th, 2013, 12:12 PM
gw1500se gw1500se is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,886 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 22 m 27 sec
Reputation Power: 581
First if you are just learning PHP do not use the deprecated mysql extensions. Learn PDO and OOP.

Second, don't make people go to another web site to look at your code (most probably won't). Post all the code here using [ PHP ] tags which formats your code for easy reading. See the sticky at the top of this forum.

Third, it is not clear what you are trying to put in the email. You are not using the query results anywhere so you need to clarify what you are trying to do.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old January 5th, 2013, 12:25 PM
sandipcd sandipcd is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 sandipcd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 35 sec
Reputation Power: 0
In the email I want to put the data which have been filled by the last form submitter. How I shall use the query results? How I put the last mysql data in the email as inline text?

Ok, here is the full code.

Code:
<?php

define('DB_NAME', 'sandi565_form11');
define('DB_USER', 'XXXXXXX');
define('DB_PASSWORD', 'XXXXXXX');
define('DB_HOST', 'localhost');

$link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);

if (!$link) {
	die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) {
	die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}

//Start Posting the data in Mysql database from Form Input

$value = $_POST['input1'];
$value2 = $_POST['MAmount'];

$sql = "INSERT INTO demo (input1, MAmount) VALUES ('$value', '$value2')";

if (!mysql_query($sql)) {
	die('Error: ' . mysql_error());
	
}

//start print the database

$data = mysql_query("SELECT * FROM demo ORDER BY ID DESC LIMIT 1")
 or die(mysql_error()); 
 Print "<table border cellpadding=3>"; 
 while($info = mysql_fetch_array( $data )) 
 { 
 Print "<tr>"; 
 Print "<th>ID:</th> <td>".$info['ID'] . "</td> "; 
 Print "<th>Input1:</th> <td>".$info['input1'] . "</td> "; 
 Print "<th>MAmount:</th> <td>".$info['MAmount'] . " </td></tr>"; 
 } 
 Print "</table>"; 

mysql_close();

  
//end print the database on form processing page
  
//start emailing the data
  

date_default_timezone_set('Asia/Kolkata');

require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

//$body             = "gdssdh";
//$body             = preg_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "ssl://XXXXXXX.XXXXXXX.org"; // SMTP server
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "XXXXXXX.XXXXXXX.org";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "contact@XXXXXXX.com";  // GMAIL username
$mail->Password   = "XXXXXXX";            // GMAIL password

$mail->SetFrom('contact@XXXXXXXX.com', 'HAL');

//$mail->AddReplyTo("user2@gmail.com', 'First Last");

$mail->Subject    = "Halmira 469";

//THE PROBLEM IS HERE WHEN I WANT TO SEND THE DATA AS INLINE TEXT TO EMAIL FROM MYSQL IT IS NOT WORKING. ONLY "PRINT THE DATA" IS SENDING TO EMAIL.

$body                = 'Print the data';
mysql_connect("localhost","XXXXXXX","XXXXXXX");
@mysql_select_db("sandi565_form11");
$query["SELECT * FROM demo ORDER BY ID DESC LIMIT 1"];
$result = mysql_query($query);

//while ($row = mysql_fetch_array ($result)) {
//  $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  $mail->MsgHTML($body);
  $address = "XXXXXXX@gmail.com";
  $mail->AddAddress($address, "user2");

//$mail->AddAttachment("images/phpmailer.gif");      // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

?>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > How to send mysql data to email after submitting the form?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap