Advertisement
mogra

Untitled

Nov 17th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.33 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(0);
  4. ini_set('display_errors', '0');
  5.  
  6. ob_start();
  7.  
  8. //extract all form values into variables by key name. I.E. $_POST["from_name"] becomes $from_name
  9. extract($_POST);
  10.  
  11. //Initialize non-form variables.
  12. $valid    = false;
  13. $sent     = false;
  14. $html     = '';
  15. $from     = '';
  16. $to       = '';
  17. $cc       = '';
  18. $bcc      = '';
  19. $headers  = '';
  20. $response = '';
  21.  
  22.  
  23.  
  24.  
  25. //Check if extract worked and if not spam.
  26. if (isset($special) && $special == "")
  27. {
  28.     //Check required fields, $from_name cannot be empty, and if $preferred is "phone" neither can
  29.     //$from_phone, otherwise neither can $from_email
  30.     $valid = (trim($from_name) != ""  &&
  31.              (($preferred == "phone"  && trim($from_phone) != "") || (trim($from_email) != "")) &&
  32.              (trim($from_city) != "") && (trim($from_zip) != "")  &&  
  33.              (trim($to_city) !="")    && (trim($to_zip) ! ="")    &&
  34.          (($hazard != "checked")  ||
  35.              (trim($hclass) != "" && trim($un) != ""))
  36.              );
  37.  
  38.  
  39.     if ($valid)
  40.     {
  41.         //Build the HTML Body of the email
  42.         $html = <<<EOT
  43. <h1>Pronto Quote Request Email</h1>
  44.  
  45. <h2>From:</h2>
  46.  
  47. <p><b>Requested by:</b> $from_name</p>
  48. <p><b>Company:</b> $from_contact</p>
  49. <p><b>City:</b> $from_city</p>
  50. <p><b>State:</b> $from_state</p>
  51. <p><b>Zip Code:</b> $from_zipcode</p>
  52. <p><b>Country:</b> $from_country</p>
  53. <p><b>Phone:</b> $from_phone</p>
  54. <p><b>Email:</b> $from_email</p>
  55. <p><b>Preferred:</b> $preferred</p>
  56.  
  57. <h2>To:</h2>
  58.  
  59. <p><b>City:</b> $to_city</p>
  60. <p><b>State:</b> $to_state</p>
  61. <p><b>Zip Code:</b> $to_zipcode</p>
  62. <p><b>Country:</b> $to_country</p>
  63.  
  64. <h2>Packages:</h2>
  65.  
  66. <p><b>Pieces:</b> $pieces</p>
  67. <p><b>Skid:</b> $skid</p>
  68. <p><b>Weight (Lbs):</b> $weight</p>
  69. <p><b>Dimensions:</b> $dimensions</p>
  70. <p><b>Hazardous class:</b> $hclass</p>
  71. <p><b>Hazardous UN #:</b> $un</p>
  72.  
  73. <p><b>Ready by:</b> $readyTime</p>
  74. <p><b>Deliver by:</b> $deliveryTime</p>
  75.  
  76.  
  77. <h2>Other:</h2>
  78.  
  79. <p><b>Vehicle:</b> $vehicle</p>
  80.  
  81. <h2>Comments:</h2>
  82. <p>$comment</p>
  83. EOT;
  84.  
  85.         //Setup who it goes to and comes from
  86.         //To add more to To, CC or Bcc, add strings to Array
  87.         $from = 'sales@pronto-delivery.com';
  88.         $to = array(
  89.          //       'sales@pronto-delivery.com',
  90.           'hrozo@hatalasystemsgroup.com',
  91.               );
  92.         $cc = array(
  93.            //     'jack.chambers@pronto-deliver.com',
  94.               );
  95.         $bcc = array(
  96.         //      'hrozo@hatalasystemsgroup.com',
  97.         //   'cwrinn@hatalasystemsgroup.com',
  98.                );
  99.  
  100.         //Set to HTML email
  101.         $headers = 'MIME-Version: 1.0' . "\r\n";
  102.         $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  103.  
  104.         //Additional headers for From, Cc, Bcc and Mailer
  105.         $headers .= 'From: ' . $from . "\r\n";
  106.         $headers .= 'Cc: ' . join(';', $cc) . "\r\n";
  107.         $headers .= 'Bcc: ' . join(';', $bcc) . "\r\n";
  108.         $headers .= 'X-Mailer: PHP/' . phpversion();
  109.  
  110.         $subject = "Quote Request: $from";
  111.  
  112.         //attempt to send email
  113.         print($html); $sent = true;
  114.         //$sent = mail(join(';', $to), $subject, $html, $headers);
  115.         if ($sent)
  116.         {
  117.             //Email send successful
  118.             $response = 'Thank you for your request.<br>'.
  119.             'A Customer Service representative will respond shortly with the information.';
  120.         }
  121.         else
  122.         {
  123.             //Email send unsuccessful
  124.             $response = 'There was a problem sending the email. Please try again.';
  125.         }
  126.     }
  127.     else
  128.     {
  129.         $response = 'Missing Required Fields. Please ensure Name and either Phone or Email are filled in.';
  130.     }
  131. }
  132. else
  133. {
  134.     $response = 'No Spam Allowed!';
  135. }
  136.  
  137. print($response);
  138.  
  139. //Log
  140. $log_data = array(
  141.     "Date"       => date("Ymd\TT"),
  142.     "User Agent" => $_SERVER["HTTP_USER_AGENT"],
  143.     "SpamString" => (isset($special))?$special:'',
  144.     "Validates"  => ($valid)?"True":"False",
  145.     "From"       => $from,
  146.     "To"         => join(';', $to),
  147.     "Cc"         => join(';', $cc),
  148.     "Bcc"        => join(';', $bcc),
  149.     "Message"    => str_replace("\n", "<br>", htmlspecialchars($html)),
  150.     "Response"   => htmlspecialchars($response),
  151.     "Sent"       => ($sent)?"True":"False",
  152. );
  153.  
  154. file_put_contents('./quoterequest.log', json_encode($log_data) . "$||$", FILE_APPEND);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement