Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. function custom_mail ($to, $subject, $message, $additional_headers, $additional_parameters)
  2. {
  3. /*\AddMessage2Log(
  4. 'To: '.$to.PHP_EOL.
  5. 'Subject: '.$subject.PHP_EOL.
  6. 'Message: '.$message.PHP_EOL.
  7. 'Headers: '.$additional_headers.PHP_EOL.
  8. 'Params: '.$additional_parameters.PHP_EOL
  9. );*/
  10.  
  11. require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
  12. $to = str_replace(' ','',$to);
  13. $mail = new PHPMailer;
  14. $mail->CharSet = 'UTF-8';
  15. $address = explode(',', $to);
  16. foreach ($address as $addr)
  17. $mail->addAddress($addr);
  18.  
  19. // Просматриваем заголовки на предмет аттачей
  20. $headers = explode("\n", $additional_headers);
  21. // Определить аттачи легко - передается сепаратор таким вот образом
  22. $attachHeader = 'Content-Type: multipart/mixed; boundary=';
  23. foreach( $headers as $h )
  24. {
  25. // Если есть заголовок с ограничиителем
  26. if( stripos($h, $attachHeader) === 0 )
  27. {
  28. // Вытаскиваем значение сепаратора
  29. $bndr = substr($h, strlen($attachHeader));
  30. $bndr = trim($bndr, '"');
  31. // И дублируем его же, но в свойство phpMailer.
  32. $mail->ContentType = 'multipart/mixed; boundary="' . $bndr . '"';
  33. // I know its dirty hack
  34. break;
  35. }
  36. }
  37.  
  38.  
  39. if (substr_count($message, "Content-Type: text/html"))
  40. {
  41.  
  42. // $mail->Encoding = '8bit';
  43. }
  44. else
  45. {
  46. // $mail->Encoding = '8bit';
  47. //$mail->isHTML(true); // Set email format to HTML
  48. }
  49.  
  50. $mail->Subject = $subject;
  51. $mail->Body = $message;
  52.  
  53. if( defined('PROJECT_SMTP_HOST') )
  54. {
  55. $mail->IsSMTP();
  56. $mail->SMTPDebug = defined('PROJECT_SMTP_DEBUG_LEVEL') ? PROJECT_SMTP_DEBUG_LEVEL : 0; // enables SMTP debug information (for testing)
  57. $mail->Host = PROJECT_SMTP_HOST;
  58. $mail->SMTPAuth = true; // enable SMTP authentication
  59. $mail->Username = PROJECT_SMTP_USERNAME;
  60. $mail->Password = PROJECT_SMTP_PASSWORD;
  61. $mail->From = PROJECT_SMTP_FROM;
  62. $mail->FromName = PROJECT_SMTP_FROMNAME;
  63. $mail->SMTPSecure = PROJECT_SMTP_SECURITY; // "tls" or "ssl"
  64. $mail->Port = PROJECT_SMTP_PORT;
  65. //HACK: Dirty hack! if ssl not configured at hosting
  66. $mail->SMTPOptions = array(
  67. 'ssl' => array(
  68. 'verify_peer' => false,
  69. 'verify_peer_name' => false,
  70. 'allow_self_signed' => true
  71. ),
  72. );
  73. }
  74.  
  75. if( !$mail->send() )
  76. {
  77. \AddMessage2Log('Mailer Error: ' . $mail->ErrorInfo);
  78. return false;
  79. }
  80.  
  81. return true;
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement