Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
How To Send MYSQL Data To An Email
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="rasputin009" data-source="post: 484414" data-attributes="member: 129375"><p>After the customer fills the form, the form data is sent to mysql and an email gets sent to me with the last form data that the customer submitted. But, the email "last mysql data" is not going as inline text. Please help me. Sample code is given below.</p><p></p><p><?php</p><p>define('DB_NAME', 'XXXXXXX');</p><p>define('DB_USER', 'XXXXXXX');</p><p>define('DB_PASSWORD', 'XXXXXXX');</p><p>define('DB_HOST', 'localhost');</p><p>$link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);</p><p>if (!$link) {</p><p>die('Could not connect: ' . mysql_error());</p><p>}</p><p>$db_selected = mysql_select_db(DB_NAME, $link);</p><p>if (!$db_selected) {</p><p>die('Can\'t use ' . DB_NAME . ': ' . mysql_error());</p><p>}</p><p>//Start Posting the data in Mysql database from Form Input</p><p>$value = $_POST['input1'];</p><p>$value2 = $_POST['MAmount'];</p><p>$sql = "INSERT INTO demo (input1, MAmount) VALUES ('$value', '$value2')";</p><p>if (!mysql_query($sql)) {</p><p>die('Error: ' . mysql_error());</p><p>}</p><p>//start print the database</p><p>$data = mysql_query("SELECT * FROM demo ORDER BY ID DESC LIMIT 1")</p><p>or die(mysql_error());</p><p>Print "<table border cellpadding=3>";</p><p>while($info = mysql_fetch_array( $data ))</p><p>{</p><p>Print "<tr>";</p><p>Print "<th>ID:</th> <td>".$info['ID'] . "</td> ";</p><p>Print "<th>Input1:</th> <td>".$info['input1'] . "</td> ";</p><p>Print "<th>MAmount:</th> <td>".$info['MAmount'] . " </td></tr>";</p><p>}</p><p>Print "</table>";</p><p>mysql_close();</p><p>//end print the database on form processing page</p><p>//start emailing the data</p><p>date_default_timezone_set('Asia/Kolkata');</p><p>require_once('class.phpmailer.php');</p><p>//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded</p><p>$mail = new PHPMailer();</p><p>//$body = "gdssdh";</p><p>//$body = preg_replace("[\]",'',$body);</p><p>$mail->IsSMTP(); // telling the class to use SMTP</p><p>$mail->Host = "ssl://XXXXXXX.XXXXXXX.org"; // SMTP server</p><p>$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)</p><p>// 1 = errors and messages</p><p>// 2 = messages only</p><p>$mail->SMTPAuth = true; // enable SMTP authentication</p><p>$mail->SMTPSecure = "ssl"; // sets the prefix to the servier</p><p>$mail->Host = " <a href="https://www.astaguru.com/" target="_blank">https://www.astaguru.com/</a> "; // sets GMAIL as the SMTP server</p><p>$mail->Port = 465; // set the SMTP port for the GMAIL server</p><p>$mail->Username = "XXXXXXX.com"; // GMAIL username</p><p>$mail->Password = "XXXXXXX"; // GMAIL password</p><p>$mail->SetFrom('<a href="mailto:contact@XXXXXXXX.com">contact@XXXXXXXX.com</a>', 'HAL');</p><p>//$mail->AddReplyTo("XXXXXXX', 'First Last");</p><p>$mail->Subject = "XXXXXXX";</p><p>//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.</p><p>$body = 'Print the data';</p><p>mysql_connect("localhost","XXXXXXX","XXXXXXX");</p><p>@mysql_select_db("XXXXXXX");</p><p>$query["SELECT * FROM demo ORDER BY ID DESC LIMIT 1"];</p><p>$result = mysql_query($query);</p><p>//while ($row = mysql_fetch_array ($result)) {</p><p>// $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test</p><p>$mail->MsgHTML($body);</p><p>$address = "XXXXXXX";</p><p>$mail->AddAddress($address, "user2");</p><p>//$mail->AddAttachment("images/phpmailer.gif"); // attachment</p><p>//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment</p><p>if(!$mail->Send()) {</p><p>echo "Mailer Error: " . $mail->ErrorInfo;</p><p>} else {</p><p>echo "Message sent!";</p><p>}</p><p>?></p></blockquote><p></p>
[QUOTE="rasputin009, post: 484414, member: 129375"] After the customer fills the form, the form data is sent to mysql and an email gets sent to me with the last form data that the customer submitted. But, the email "last mysql data" is not going as inline text. Please help me. Sample code is given below. <?php define('DB_NAME', 'XXXXXXX'); 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 = " [URL]https://www.astaguru.com/[/URL] "; // sets GMAIL as the SMTP server $mail->Port = 465; // set the SMTP port for the GMAIL server $mail->Username = "XXXXXXX.com"; // GMAIL username $mail->Password = "XXXXXXX"; // GMAIL password $mail->SetFrom('[email]contact@XXXXXXXX.com[/email]', 'HAL'); //$mail->AddReplyTo("XXXXXXX', 'First Last"); $mail->Subject = "XXXXXXX"; //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("XXXXXXX"); $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"; $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!"; } ?> [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
How To Send MYSQL Data To An Email
Top