472,344 Members | 1,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,344 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 4254

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...
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...
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...
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...
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...
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...
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...
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...
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....
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.