Advertisement
webpagefxjared

Untitled

Jul 22nd, 2011
536
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 = 'mgates@clevelandbrothers.com, Kathy_Williams@Whayne.com';
  63. //$to = 'curt@webpagefx.com';
  64.  
  65. //define the subject of the email
  66. $subject = 'CDUPA Conference Registration';
  67.  
  68. //create a boundary string. It must be unique
  69. //so we use the MD5 algorithm to generate a random hash
  70. $random_hash = md5(date('r', time()));
  71.  
  72. //define the headers we want passed. Note that they are separated with \r\n
  73. $headers = "From: webmaster@eclevelandbrothers.com";
  74.  
  75. //add boundary string and mime type specification
  76. $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
  77.  
  78. //read the atachment file contents into a string,
  79. //encode it with MIME base64,
  80. //and split it into smaller chunks
  81. $attachment = chunk_split(base64_encode($csv));
  82. //define the body of the message.
  83. ob_start(); //Turn on output buffering
  84. ?>
  85. --PHP-mixed-<?php echo $random_hash; ?>  
  86. Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
  87.  
  88. --PHP-alt-<?php echo $random_hash; ?>  
  89. Content-Type: text/plain; charset="iso-8859-1"
  90. Content-Transfer-Encoding: 7bit
  91.  
  92. Conference Registration
  93. =======================
  94.  
  95. The following person has registered for the 2011 CDUPA Conference:
  96.  
  97. <?php echo $registration ?>
  98.  
  99. --PHP-alt-<?php echo $random_hash; ?>  
  100. Content-Type: text/html; charset="iso-8859-1"
  101. Content-Transfer-Encoding: 7bit
  102.  
  103. <h2>Conference Registration</h2>
  104.  
  105. <p>The following person has registered for the 2011 CDUPA Conference:</p>
  106.  
  107. <p>
  108. <?php echo nl2br($registration); ?>
  109. </p>
  110.  
  111. --PHP-alt-<?php echo $random_hash; ?>--
  112.  
  113. --PHP-mixed-<?php echo $random_hash; ?>  
  114. Content-Type: application/csv; name="cdupa_registrations.csv"  
  115. Content-Transfer-Encoding: base64  
  116. Content-Disposition: attachment  
  117.  
  118. <?php echo $attachment; ?>
  119. --PHP-mixed-<?php echo $random_hash; ?>--
  120.  
  121. <?php
  122. //copy current buffer contents into $message variable and delete current output buffer
  123. $message = ob_get_clean();
  124. //send the email
  125. $mail_sent = @mail( $to, $subject, $message, $headers );
  126.  
  127. header('Location: thankyou.html');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement