Guest User

Untitled

a guest
Jun 20th, 2016
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. <?php
  2. /*
  3. Copyright © Amirol Zolkifli & SistemBorang.com
  4. Author: Amirol Zolkifli
  5. URL: http://fb.com/amirolzolkifli
  6. License: For your personal use only
  7. */
  8.  
  9. require 'mail/PHPMailerAutoload.php';
  10.  
  11. require 'borang-konfigurasi.php';
  12.  
  13. // Validate form submission
  14. if( ! isset( $_POST['form_submit'] ) OR $_POST['form_submit'] != 'true' )
  15. {
  16. $error = 'Sila isi borang dengan lengkap.';
  17. include 'borang-error.php';
  18. exit();
  19. }
  20.  
  21. // Define variables
  22. $customer_name = $_POST['customer_name'];
  23. $customer_email = $_POST['customer_email'];
  24. $customer_phone = $_POST['customer_phone'];
  25. $customer_address = $_POST['customer_address'];
  26. $model_kereta = $_POST['model_kereta'];
  27.  
  28. // Validation
  29. $error = '';
  30.  
  31. if( $customer_name == '' )
  32. {
  33. $error .= 'Sila isi nama anda<br /><br />';
  34. }
  35.  
  36. if( $customer_email == '' )
  37. {
  38. $error .= 'Sila isi alamat emel anda<br /><br />';
  39. }
  40.  
  41. if( $customer_phone == '' )
  42. {
  43. $error .= 'Sila isi nombor telefon anda<br /><br />';
  44. }
  45.  
  46. if( $customer_address == '' )
  47. {
  48. $error .= 'Sila isi alamat rumah anda<br /><br />';
  49. }
  50. if( $model_kereta == '' )
  51. {
  52. $error .= 'Sila pilih model kereta anda<br /><br />';
  53. }
  54.  
  55. if( $error != '' )
  56. {
  57. $error = 'Error with your form. Please go back.';
  58. include 'borang-error.php';
  59. exit();
  60. }
  61.  
  62. // Set email
  63. $email_subject = 'Terima kasih untuk email anda';
  64.  
  65. $email_content = "
  66. Terima kasih untuk kiriman borang.
  67. <br /><br />
  68. Berikut adalah data kiriman borang daripada $customer_name;
  69. <br /><br />
  70. =========================
  71. <br /><br />
  72. Nama: $customer_name
  73. <br />
  74. Email: $customer_email
  75. <br />
  76. No. Telefon: $customer_phone
  77. <br />
  78. Alamat:
  79. <br />
  80. $customer_address
  81. <br /><br />
  82.  
  83. Model Kereta: $model_kereta
  84. <br />
  85.  
  86.  
  87. <br />
  88. <br />
  89. <br />
  90. Sila rujuk attachment dibawah ini:
  91.  
  92.  
  93.  
  94. ";
  95.  
  96. // Process form
  97. $mail = new PHPMailer;
  98.  
  99. $mail->isSMTP(); // Set mailer to use SMTP
  100. $mail->Host = $mail_host; // Specify main and backup SMTP servers
  101. $mail->SMTPAuth = $mail_auth; // Enable SMTP authentication
  102. $mail->Username = $mail_username; // SMTP username
  103. $mail->Password = $mail_password; // SMTP password
  104. $mail->SMTPSecure = 'tls';
  105.  
  106. $mail->From = $email_from;
  107. $mail->FromName = $customer_name;
  108. $mail->addAddress($email_replyTo, $email_name); // Add a recipient
  109. $mail->addReplyTo($customer_email, $customer_name);
  110. $mail->addCC($customer_email, $customer_name);
  111.  
  112. // Attachment
  113. if( isset($_FILES['attachments']) )
  114. {
  115. $name_array = $_FILES['attachments']['name'];
  116. $tmp_name_array = $_FILES['attachments']['tmp_name'];
  117. $type_array = $_FILES['attachments']['type'];
  118. $size_array = $_FILES['attachments']['size'];
  119. $error_array = $_FILES['attachments']['error'];
  120.  
  121. for($i = 0; $i < count($tmp_name_array); $i++){
  122. $mail->AddAttachment( $tmp_name_array[$i], $name_array[$i]);
  123. }
  124.  
  125. }
  126.  
  127. $mail->isHTML(true); // Set email format to HTML
  128.  
  129. $mail->Subject = $email_subject;
  130. $mail->Body = $email_content;
  131. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  132.  
  133. if( !$mail->send() ) {
  134. echo 'Message could not be sent.';
  135. echo 'Mailer Error: ' . $mail->ErrorInfo;
  136. } else {
  137. header('location: '. $thankyou_page);
  138. }
  139.  
  140. ?>
Add Comment
Please, Sign In to add comment