Advertisement
Guest User

Untitled

a guest
Aug 20th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <?php
  2.  
  3. function sendEmail($admin_email, $site_name, $form_subject, $email, $name){
  4. require get_template_directory() . '/libs/phpmailer/PHPMailerAutoload.php';
  5. $c = true;
  6. $message = "";
  7. foreach ( $_POST as $key => $value ) {
  8. if ( $value != "" && $value != "0" && $key != "site_name" && $key != "admin_email"
  9. && $key != "form_subject" && $key != "type" && $key != "files" && $key != "action") {
  10. $key = translate_word_in_rus($key);
  11. $message .= "
  12. " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
  13. <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
  14. <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
  15. </tr>";
  16. }
  17. }
  18.  
  19. $mail = new PHPMailer();
  20. $mail->isSMTP();
  21. $mail->Host = 'smtp.gmail.com';
  22. $mail->SMTPAuth = true;
  23. $mail->Username = $admin_email;
  24. $mail->Password = 'your_gmail_password';
  25. $mail->SMTPSecure = 'tls';
  26. $mail->Port = 587;
  27. $mail->CharSet = 'UTF-8';
  28.  
  29. $mail->setFrom($email, $site_name);
  30. $mail->addAddress($admin_email);
  31. $mail->isHTML(true);
  32.  
  33. $mail->Subject = $name . " - " . $form_subject;
  34.  
  35. if(isset($_FILES["files"])){
  36. foreach($_FILES["files"]["tmp_name"] as $key => $tmp_name ){
  37. $file_name = $_FILES["files"]["name"][$key];
  38. $file_size = $_FILES["files"]["size"][$key];
  39. $file_tmp = $_FILES["files"]["tmp_name"][$key];
  40. $ready = isRightImage($file_size,$file_name,$file_tmp); // in data-check.php gist
  41. if($ready) $mail->AddAttachment($file_tmp, $file_name);
  42. }
  43. }
  44. $message = "<table style='width: 100%;'>$message</table>";
  45. $mail->Body = $message;
  46. $mail->send();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement