Advertisement
webpagefxjared

Untitled

Jul 22nd, 2011
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.98 KB | None | 0 0
  1. <?php
  2. include('../include/conn.php');
  3.  
  4. if (!$_POST or $_POST['name'] == '') { print "Error."; exit; }
  5. $_POST['arrival'] = date('Y-m-d', strtotime($_POST['arrival']));
  6. $_POST['departure'] = date('Y-m-d', strtotime($_POST['departure']));
  7. $_POST['ducky'] = $_POST['ducky'] ? 'Yes' : 'No';
  8. $_POST['golf'] = $_POST['golf'] ? 'Yes' : 'No';
  9.  
  10. if ($_POST['ducky'] == 'No') $_POST['duckyyes'] = '';
  11. if ($_POST['golf'] == 'No') $_POST['golf'] = '';
  12. if ($_POST['bellefonte'] == 'No') $_POST['bellefonte'] = '';
  13.  
  14. $fields = array(
  15.     'name' => 'Name',
  16.     'family' => 'Family',
  17.     'title' => 'Title',
  18.     'dealership' => 'Dealership',
  19.     'address' => 'Address',
  20.     'city' => 'City/State',
  21.     'zip' => 'Zip',
  22.     'email' => 'Email',
  23.     'telephone' => 'Phone',
  24.     'arrival' => 'Arrival Date',
  25.     'departure' => 'Departure Date',
  26.     'golf' => 'Golf Attending',
  27.     'golfyes' => ' Golf add. people attending',
  28.     'ducky' => 'Ducky Attending',
  29.     'duckyyes' => ' Ducky add. people attending',
  30.     'bellefonte' => 'Bellefonte',
  31.     'bellefonteyes' => ' Bellefonte add. people attending',    
  32. );
  33.  
  34. $sql = 'INSERT INTO cdupa (' . implode(", ", array_keys($fields)) . ') VALUES (';  
  35. $registration = '';
  36. foreach ($fields as $f => $v)
  37. {
  38.     $sql .= "'".mysql_real_escape_string($_POST[$f])."',";
  39.     $registration .= sprintf('%s: ', ucwords($v)) . stripslashes($_POST[$f]) . "\n";
  40. }
  41. $sql = trim($sql, ',') . ")";
  42.  
  43. // Insert new record
  44. mysql_query($sql) or die(mysql_error());
  45.  
  46. $csv = implode(',',$fields) . "\n";
  47. $csv_fields = array('id', 'created_at') + array_keys($fields);
  48. $rs = mysql_query("SELECT ".implode(', ', $csv_fields)." FROM cdupa ORDER BY id") or die(mysql_error());
  49.  
  50. while ($row = mysql_fetch_row($rs))
  51. {
  52.     $csv_row = '';
  53.     foreach ($row as $col)
  54.     {
  55.         $csv_row .= '"'.str_replace('"','', $col).'",';
  56.     }
  57.     $csv .= trim($csv_row, ',') . "\n";
  58. }
  59.  
  60.  
  61. //define the receiver of the email
  62. //$to = '[email protected]';
  63.  
  64. //define the subject of the email
  65. $subject = 'CDUPA Conference Registration';
  66.  
  67. //create a boundary string. It must be unique
  68. //so we use the MD5 algorithm to generate a random hash
  69. $random_hash = md5(date('r', time()));
  70.  
  71. //define the headers we want passed. Note that they are separated with \r\n
  72. $headers = "From: [email protected]";
  73.  
  74. //add boundary string and mime type specification
  75. $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
  76.  
  77. //read the atachment file contents into a string,
  78. //encode it with MIME base64,
  79. //and split it into smaller chunks
  80. $attachment = chunk_split(base64_encode($csv));
  81. //define the body of the message.
  82. ob_start(); //Turn on output buffering
  83. ?>
  84. --PHP-mixed-<?php echo $random_hash; ?>  
  85. Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
  86.  
  87. --PHP-alt-<?php echo $random_hash; ?>  
  88. Content-Type: text/plain; charset="iso-8859-1"
  89. Content-Transfer-Encoding: 7bit
  90.  
  91. Conference Registration
  92. =======================
  93.  
  94. The following person has registered for the 2011 CDUPA Conference:
  95.  
  96. <?php echo $registration ?>
  97.  
  98. --PHP-alt-<?php echo $random_hash; ?>  
  99. Content-Type: text/html; charset="iso-8859-1"
  100. Content-Transfer-Encoding: 7bit
  101.  
  102. <h2>Conference Registration</h2>
  103.  
  104. <p>The following person has registered for the 2011 CDUPA Conference:</p>
  105.  
  106. <p>
  107. <?php echo nl2br($registration); ?>
  108. </p>
  109.  
  110. --PHP-alt-<?php echo $random_hash; ?>--
  111.  
  112. --PHP-mixed-<?php echo $random_hash; ?>  
  113. Content-Type: application/csv; name="cdupa_registrations.csv"  
  114. Content-Transfer-Encoding: base64  
  115. Content-Disposition: attachment  
  116.  
  117. <?php echo $attachment; ?>
  118. --PHP-mixed-<?php echo $random_hash; ?>--
  119.  
  120. <?php
  121. //copy current buffer contents into $message variable and delete current output buffer
  122. $message = ob_get_clean();
  123. //send the email
  124. $mail_sent = @mail( $to, $subject, $message, $headers );
  125.  
  126. header('Location: thankyou.html');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement