By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,738 Members | 1,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,738 IT Pros & Developers. It's quick & easy.

Script send mail and save into mysql db

P: 1
Hello,

I have a script php that I use on my website to permit visitors to send me some email with some data, this is the html table code:

Expand|Select|Wrap|Line Numbers
  1. <table width="730" border="0" cellpadding="0" cellspacing="0">
  2.           <tr>
  3.             <td><div align="center" class="textorange1"><strong>Richiesta Ricarica</strong></div></td>
  4.           </tr>
  5.           <tr>
  6.             <td>&nbsp;</td>
  7.           </tr>
  8.           <tr>
  9.             <td><div align="center" class="textblack1">Prima di compilare questo form bisogna effettuare le registrazioni come indicato nel regolamento, poi compilare tutti i campi o la richiesta di ricarica non verrą accettata.</div></td>
  10.           </tr>
  11.           <tr>
  12.             <td>&nbsp;</td>
  13.           </tr>
  14.           <tr>
  15.             <td><div align="center">
  16.               <div align="center">
  17.                 <form id="commentform" name="commentform" method="post" action="ricarica.php">
  18.                   <table width="500" border="0" cellspacing="0" cellpadding="0">
  19.                     <tr align="left" valign="middle">
  20.                       <td width="170" height="20" class="textblack1"><div align="left">Nome  *:</div></td>
  21.                       <td width="120"><div align="left">
  22.                         <input name="nome" type="text" class="inputdepartment" id="nome" size="20" />
  23.                       </div></td>
  24.                     </tr>
  25.                     <tr align="left" valign="middle">
  26.                       <td height="20" class="textblack1"><div align="left">Cognome *:</div></td>
  27.                       <td><div align="left">
  28.                         <input name="cognome" type="text" class="inputdepartment" id="cognome" size="20" />
  29.                       </div></td>
  30.                     </tr>
  31.                     <tr align="left" valign="middle">
  32.                       <td height="20" class="textblack1"><div align="left">Data di nascita *:</div></td>
  33.                       <td><div align="left">
  34.                         <input name="datadinascita" type="text" class="inputdepartment" id="datadinascita" value="gg/mm/aaaa" size="20" />
  35.                       </div></td>
  36.                     </tr>
  37.                     <tr align="left" valign="middle">
  38.                       <td height="20" class="textblack1"><div align="left">Sesso *:</div></td>
  39.                       <td><div align="left">
  40.                         <select name="sesso" id="sesso" class="inputdepartment">
  41.                           <option value="-------" selected="selected">-------</option>
  42.                           <option value="Maschio">Maschio</option>
  43.                           <option value="Femmina">Femmina</option>
  44.                         </select>
  45.                       </div></td>
  46.                     </tr>
  47.                     <tr align="left" valign="middle">
  48.                       <td height="20" class="textblack1"><div align="left">Indirizzo *:</div></td>
  49.                       <td><div align="left">
  50.                         <input name="indirizzo" type="text" class="inputdepartment" id="indirizzo" size="20" />
  51.                       </div></td>
  52.                     </tr>
  53.                     <tr align="left" valign="middle">
  54.                       <td height="20" class="textblack1"><div align="left">CAP *:</div></td>
  55.                       <td><div align="left">
  56.                         <input name="cap" type="text" class="inputdepartment" id="cap" size="20" />
  57.                       </div></td>
  58.                     </tr>
  59.                     <tr align="left" valign="middle">
  60.                       <td height="20" class="textblack1"><div align="left">Provincia  *:</div></td>
  61.                       <td><div align="left">
  62.                         <input name="provincia" type="text" class="inputdepartment" id="provincia" size="20" />
  63.                       </div></td>
  64.                     </tr>
  65.                     <tr align="left" valign="middle">
  66.                       <td height="20" class="textblack1"><div align="left">Comune *:</div></td>
  67.                       <td><div align="left">
  68.                         <input name="comune" type="text" class="inputdepartment" id="comune" size="20" />
  69.                       </div></td>
  70.                     </tr>
  71.  
  72.                     <tr align="left" valign="middle">
  73.                       <td height="20" class="textblack1"><div align="left">Numero cellulare/carta da ricaricare/email Paypal *:</div></td>
  74.                       <td><div align="left">
  75.                         <input name="ricarica" type="text" class="inputdepartment" id="ricarica" size="20" />
  76.                       </div></td>
  77.                     </tr>
  78.                     <tr align="left" valign="middle">
  79.                       <td height="20" class="textblack1"><div align="left">Il suo indirizzo e-mail *: </div></td>
  80.                       <td><div align="left">
  81.                         <input name="email" type="text" class="inputdepartment" id="email" size="20" />
  82.                       </div></td>
  83.                     </tr>
  84.                     <tr align="left" valign="middle">
  85.                       <td height="20" class="textblack1"><div align="left">Conferma indirizzo e-mail *: </div></td>
  86.                       <td><div align="left">
  87.                         <input name="email" type="text" class="inputdepartment" id="email" size="20" />
  88.                       </div></td>
  89.                     </tr>
  90.                     <tr align="left" valign="middle">
  91.                       <td height="20" class="textblack1"><div align="left">Orario registrazione *:</div></td>
  92.                       <td><div align="left">
  93.                         <input name="orario" type="text" class="inputdepartment" id="orario" value="XX:XX" size="20" />
  94.                       </div></td>
  95.                     </tr>
  96.  
  97.  
  98.                     <tr align="left" valign="middle">
  99.                       <td height="20" class="textblack1"><div align="left">Data registrazione *:</div></td>
  100.                       <td><div align="left">
  101.                         <input name="data" type="text" class="inputdepartment" id="data" value="gg/mm/aaaa" size="20" />
  102.                       </div></td>
  103.                     </tr>
  104.                     <tr align="left" valign="middle">
  105.                       <td height="20" class="textblack1"><div align="left">Operatore *:</div></td>
  106.                       <td><div align="left">
  107.                         <select name="operatore" id="operatore" class="inputdepartment">
  108.                           <option value="-------" selected="selected">-------</option>
  109.                           <option value="Tim">Tim</option>
  110.                           <option value="Vodafone">Vodafone</option>
  111.                           <option value="Wind">Wind</option>
  112.                           <option value="Tre">Tre</option>
  113.                           <option value="PosteMobile">PosteMobile</option>
  114.                           <option value="PostePay">PostePay</option>
  115.                           <option value="Paypal">Paypal</option>
  116.                           <option value="MediasetPremium">MediasetPremium</option>
  117.                         </select>
  118.                       </div></td>
  119.                     </tr>
  120.                     <tr align="left" valign="middle">
  121.                       <td height="20" class="textblack1"><div align="left">Come ci hai conosciuto *: </div></td>
  122.                       <td><div align="left">
  123.                         <select name="know" id="know" class="inputdepartment">
  124.                           <option value="-------" selected="selected">-------</option>
  125.                           <option value="Google">Google</option>
  126.                           <option value="Yahoo">Yahoo</option>
  127.                           <option value="Amici">Amici</option>
  128.                           <option value="Parenti">Parenti</option>
  129.                           <option value="Altro">Altro</option>
  130.                         </select>
  131.                       </div></td>
  132.                     </tr>
  133.  
  134.                     <tr align="left" valign="middle">
  135.                       <td class="textblack1"><div align="left">Media partners su cui ci si č iscritti:
  136.  *:</div></td>
  137.                       <td><div align="left">
  138.                         <textarea name="msg" cols="35" rows="10" class="inputtextarea" id="msg"></textarea>
  139.                       </div></td>
  140.                     </tr>
  141.                   </table>
  142.                   <table border="0" cellpadding="0" cellspacing="0" width="500">
  143.                     <tr align="center" valign="middle">
  144.                       <td height="30">
  145.                           <div align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  146.                             <input onclick="return confirm('Siete sicuri di aver effettuato le registrazioni ai media partner come indicato nel regolamento? Se non l\'avete fatto la richiesta non sarą accettata.');" name="Submit" type="submit" class="inputbutton" value="Invia" />
  147.                             <input name="Submit2" type="reset" class="inputbutton" value="Reset" />
  148.                           </div></td>
  149.                     </tr>
  150.                     <tr align="left" valign="top">
  151.                       <td height="20"><div class="textblack1">
  152.                         <div align="left"><strong>* Richiesto</strong></div>
  153.                       </div></td>
  154.                     </tr>
  155.                   </table>
  156.                 </form>
  157.               </div>
  158.             </div></td>
  159.           </tr>
  160.           <tr>
  161.             <td>&nbsp;</td>
  162.           </tr>
  163.           <tr>
  164.             <td><div align="center">Inviando la richiesta si accettano il <a href="regolamento.html" target="_blank" class="textorange1"><strong>regolamento</strong></a> e le <a href="faq.html" target="_blank" class="textorange1"><strong>faq</strong></a>.</div></td>
  165.           </tr>
  166.         </table>


and this is the php code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4.  
  5. <title>Mail</title>
  6.  
  7. <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
  8.  
  9. <style type="text/css">
  10.  
  11. <!--
  12.  
  13.  
  14.  
  15. .mini {
  16.  
  17.     font-family: Tahona, Verdana;
  18.  
  19.     font-size: 11px;
  20.  
  21.         color: #333333;
  22.  
  23. }
  24.  
  25. body, td, th {
  26.  
  27.     font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
  28.  
  29.     font-size: 11px;
  30.  
  31.     color: #333333;
  32.  
  33. }
  34.  
  35. a:link {
  36.  
  37.     text-decoration: none;
  38.  
  39. }
  40.  
  41. a:visited {
  42.  
  43.     text-decoration: none;
  44.  
  45. }
  46.  
  47. a:hover {
  48.  
  49.     text-decoration: underline;
  50.  
  51. }
  52.  
  53. a:active {
  54.  
  55.     text-decoration: none;
  56.  
  57. }
  58.  
  59. body {
  60.  
  61.     margin:50px; background-color: #ffffff
  62.  
  63. }
  64.  
  65. .status {
  66.  
  67.     font-size: 11px;
  68.  
  69.     color: #FF7E00;
  70.  
  71. }
  72.  
  73. -->
  74.  
  75.  
  76.  
  77. </style>
  78.  
  79. <div class="message">
  80.  
  81. <?php
  82.  
  83.  
  84.  
  85. $receiverMail    = "info@ricarica-gratis.com";
  86.  
  87. $nome        = ltrim(rtrim(strip_tags(stripslashes($_POST['nome']))));
  88.  
  89. $cognome    = ltrim(rtrim(strip_tags(stripslashes($_POST['cognome']))));
  90.  
  91. $datadinascita    = ltrim(rtrim(strip_tags(stripslashes($_POST['datadinascita']))));
  92.  
  93. $sesso      = ltrim(rtrim(strip_tags(stripslashes($_POST['sesso']))));
  94.  
  95. $indirizzo    = ltrim(rtrim(strip_tags(stripslashes($_POST['indirizzo']))));
  96.  
  97. $cap        = ltrim(rtrim(strip_tags(stripslashes($_POST['cap']))));
  98.  
  99. $provincia    = ltrim(rtrim(strip_tags(stripslashes($_POST['provincia']))));
  100.  
  101. $comune     = ltrim(rtrim(strip_tags(stripslashes($_POST['comune']))));
  102.  
  103. $ricarica    = ltrim(rtrim(strip_tags(stripslashes($_POST['ricarica']))));
  104.  
  105. $email        = ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));
  106.  
  107. $orario     = ltrim(rtrim(strip_tags(stripslashes($_POST['orario']))));
  108.  
  109. $data        = ltrim(rtrim(strip_tags(stripslashes($_POST['data']))));
  110.  
  111. $operatore    = ltrim(rtrim(strip_tags(stripslashes($_POST['operatore']))));
  112.  
  113. $know       = ltrim(rtrim(strip_tags(stripslashes($_POST['know']))));
  114.  
  115. $msg        = "Media partners su cui ci si č iscritti: \n--------------------------------------------\n".ltrim(rtrim(strip_tags($_POST['msg'])));
  116.  
  117.  
  118.  
  119. $ip        = getenv("REMOTE_ADDR");
  120.  
  121. $msgformat    = "Da: $nome $cognome - ($ip)\nData di nascita: $datadinascita\nSesso: $sesso\nIndirizzo: $indirizzo\nCAP: $cap\nProvincia: $provincia\nComune: $comune\nRicaricare: $ricarica\nEmail: $email\nOrario: $orario\nData di registrazione: $data\nOperatore: $operatore\nCome ci hai conosciuto: $know\n\n$msg";
  122.  
  123.  
  124.  
  125. // VALIDATION
  126.  
  127. if(empty($nome) || empty($cognome) || empty($datadinascita) || empty($sesso) || empty($indirizzo) || empty($cap) || empty($provincia) || empty($comune) || empty($ricarica) || empty($email) || empty($orario) || empty($data) || empty($operatore) || empty($know) || empty($msg)) {
  128.  
  129. echo "<center><b>La tua richiesta non e' stata inviata</b><p>Per favore compila tutti i campi</p><A href='javascript:history.back()' class='status'>[ Indietro ]</a><br><br></center>"; 
  130.  
  131. }
  132.  
  133. elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
  134.  
  135. echo "<center><b>La tua richiesta non e' stata inviata</b><p>L'indirizzo email non e' valido</p><A href='javascript:history.back()' class='status'>[ Indietro ]</a><br><br></center>";
  136.  
  137. }
  138.  
  139. else {
  140.  
  141.     mail($receiverMail, $operatore, $msgformat, "From: $nome <$email>");
  142.  
  143.  
  144.  
  145.     echo "<center><strong>La tua richiesta e' stata inviata!</strong><p>Ti ricontatteremo non appena possibile</p><A href='index.html' class='status'>[ Indietro ]</a><br><br></center>";
  146.  
  147.  
  148.  
  149. }
  150.  
  151. ?>
  152.  
  153. </div>
  154.  
  155. </body>
  156.  
  157. </html>

what I need from that script php is that when it send to me the mail in the same time save all data on a db, how I can modify that script to do that?

Thank you for all reply.

Michael
Dec 22 '08 #1
Share this Question
Share on Google+
1 Reply


Markus
Expert 5K+
P: 6,050
Using a database such as MySQL(i), you would create a table that has all the fields you want saving. Then you would use an SQL INSERT query to add new data to the table.

I suggest you get to grips with MySQL first.

Tutorial: MySQL Tutorial - Introduction
Dec 22 '08 #2

Post your reply

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