473,395 Members | 1,495 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,395 software developers and data experts.

How To Send MYSQL Data To The Email

After the customer fills the form on the website, 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.



Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. define('DB_NAME', 'XXXXXXX');
  4. define('DB_USER', 'XXXXXXX');
  5. define('DB_PASSWORD', 'XXXXXXX');
  6. define('DB_HOST', 'localhost');
  7.  
  8. $link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
  9.  
  10. if (!$link) {
  11. die('Could not connect: ' . mysql_error());
  12. }
  13.  
  14. $db_selected = mysql_select_db(DB_NAME, $link);
  15.  
  16. if (!$db_selected) {
  17. die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
  18. }
  19.  
  20. //Start Posting the data in Mysql database from Form Input
  21.  
  22. $value = $_POST['input1'];
  23. $value2 = $_POST['MAmount'];
  24.  
  25. $sql = "INSERT INTO demo (input1, MAmount) VALUES ('$value', '$value2')";
  26.  
  27. if (!mysql_query($sql)) {
  28. die('Error: ' . mysql_error());
  29.  
  30. }
  31.  
  32. //start print the database
  33.  
  34. $data = mysql_query("SELECT * FROM demo ORDER BY ID DESC LIMIT 1")
  35. or die(mysql_error());
  36. Print "<table border cellpadding=3>";
  37. while($info = mysql_fetch_array( $data ))
  38. {
  39. Print "<tr>";
  40. Print "<th>ID:</th> <td>".$info['ID'] . "</td> ";
  41. Print "<th>Input1:</th> <td>".$info['input1'] . "</td> ";
  42. Print "<th>MAmount:</th> <td>".$info['MAmount'] . " </td></tr>";
  43. }
  44. Print "</table>";
  45.  
  46. mysql_close();
  47.  
  48.  
  49. //end print the database on form processing page
  50.  
  51. //start emailing the data
  52.  
  53.  
  54. date_default_timezone_set('Asia/Kolkata');
  55.  
  56. require_once('class.phpmailer.php');
  57. //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  58.  
  59. $mail = new PHPMailer();
  60.  
  61. //$body = "gdssdh";
  62. //$body = preg_replace("[\]",'',$body);
  63.  
  64. $mail->IsSMTP(); // telling the class to use SMTP
  65. $mail->Host = "ssl://XXXXXXX.XXXXXXX.org"; // SMTP server
  66. $mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
  67. // 1 = errors and messages
  68. // 2 = messages only
  69. $mail->SMTPAuth = true; // enable SMTP authentication
  70. $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
  71. $mail->Host = " raunakgroup "; // sets GMAIL as the SMTP server
  72. $mail->Port = 465; // set the SMTP port for the GMAIL server
  73. $mail->Username = "XXXXXXX"; // GMAIL username
  74. $mail->Password = "XXXXXXX"; // GMAIL password
  75.  
  76. $mail->SetFrom('XXXXXXX', 'HAL');
  77.  
  78. //$mail->AddReplyTo("XXXXXXX', 'First Last");
  79.  
  80. $mail->Subject = "XXXXXXX";
  81.  
  82. //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.
  83.  
  84. $body = 'Print the data';
  85. mysql_connect("localhost","XXXXXXX","XXXXXXX");
  86. @mysql_select_db("XXXXXXX");
  87. $query["SELECT * FROM demo ORDER BY ID DESC LIMIT 1"];
  88. $result = mysql_query($query);
  89.  
  90. //while ($row = mysql_fetch_array ($result)) {
  91. // $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  92. $mail->MsgHTML($body);
  93. $address = "XXXXXXX";
  94. $mail->AddAddress($address, "user2");
  95.  
  96. //$mail->AddAttachment("images/phpmailer.gif"); // attachment
  97. //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
  98.  
  99. if(!$mail->Send()) {
  100. echo "Mailer Error: " . $mail->ErrorInfo;
  101. } else {
  102. echo "Message sent!";
  103. }
  104.  
  105. ?>
Feb 29 '20 #1
0 4573

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

Similar topics

2
by: jim west via SQLMonster.com | last post by:
I have website problems with mySQL data base, I have a website and was told the only way to change my password is within my SQL data base files and that it would be over my head buy the site maker,...
4
by: Jonah Olsson | last post by:
Dear All, I'm currently developing a solution where large amounts of personalised emails are being created (and no, this is not spam...) on the ASP.NET platform and being delivered by a Debian...
5
by: sam | last post by:
Do anyone know how to apply send datagrid via email? Any website for reference? Please advise.
0
by: Dave S | last post by:
I have a lot of forms on our web site that require the user to fill out information and submit it back to us. currently the information comes back as name value pair. The our employee's then has to...
3
by: YMPN | last post by:
Hi Everyone, I'm deen from Riyadh. Please do help me with some problem i have. I have this formview control setup to recieved inputs from user (textbox, dropdownlist, others). After...
1
by: sang | last post by:
Hi i am doing my project in Mysql and PHP. My problem is i want to send a Blob field to my email using the Php. That is i am storing Candidates Resume in Blob field(Document format). I want to...
1
by: steinwaygirl | last post by:
Hi all, I have been searching so hard for the answer to this, hopefully some of you all can help. I have created an HTML file with various forms - also included CSS and some javascript for...
1
by: Malli mindwave | last post by:
Hi, I want to send form data to given email id, I'm using mailto:ur@mail.com, but it doesn't working it dirsctly goes to localSystem A/C i.e outlook.. <form name="form1" method="post"...
2
by: Malli mindwave | last post by:
Hi, We are using the yahoowebHostiing service for my company website, In that one screen of the SendComments/FeedBack section is there, I'm basically dot.net develeoper ,but yahoowebhosting not...
3
by: sandipcd | last post by:
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.