Advertisement
Guest User

Untitled

a guest
Dec 17th, 2016
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. *
  5. $mail = new Mail;
  6. $mail->liveSmtp();
  7. $mail->template( $templt );
  8. $mail->send( array( 'to' => 'someone@mail.com' ) );
  9. */
  10. class Mail
  11. {
  12. private $template ;
  13. private $mail ;
  14. function __construct( )
  15. {
  16. $this->template = '';
  17. $this->mail = new PHPMailer( true );
  18.  
  19. }
  20.  
  21.  
  22.  
  23. public function send( array $options = array() )
  24. {
  25. $this->liveSmtp();
  26.  
  27. $options = array_merge(array(
  28. 'to' => '',
  29. 'subject' => 'StreamYou',
  30. 'to_name' => '',
  31. 'from' => "streamyoutested@outlook.com",
  32. // 'from' => EMAIL,
  33. 'from_name' => '',
  34. 'body' => $this->template,
  35. 'alt_body' =>'To view the message, please use an HTML compatible email viewer!',
  36. 'replay_to' => '',
  37. 'replay_to_name' => '',
  38. 'attachments' => array()
  39. ), $options);
  40.  
  41. try {
  42.  
  43. $this->mail->AddAddress( $options['to'], $options['to_name']);
  44. $this->mail->SetFrom( $options['from'], $options['from_name']);
  45.  
  46. if($options['replay_to'])
  47. $this->mail->AddReplyTo($options['replay_to'], $options['replay_to_name']);
  48.  
  49. $this->mail->Subject = $options['subject'];
  50. $this->mail->AltBody = $options['alt_body'];
  51. // $this->mail->MsgHTML(file_get_contents('contents.html'));
  52. // $this->mail->MsgHTML( $options['body'] );
  53. $this->mail->MsgHTML( $options['body'] );
  54.  
  55. if(count($options['attachments']))
  56. foreach ($options['attachments'] as $attachment) {
  57. $this->mail->AddAttachment( $attachment );
  58. }
  59.  
  60. // $this->mail->AddAttachment('images/phpmailer.gif');
  61. $this->mail->Send();
  62.  
  63. } catch (phpmailerException $e) {
  64. //echo $e->errorMessage(); //Pretty error messages from PHPMailer
  65. } catch (Exception $e) {
  66. // echo $e->getMessage(); //Boring error messages from anything else!
  67. }
  68.  
  69. }
  70.  
  71. public function template( $body = '' )
  72. {
  73. $template = '';
  74. $template .= file_get_contents( APP_DIR.'/app/mail/templates/mail_header.vis');
  75. $template .= $body;
  76. $template .= file_get_contents( APP_DIR.'/app/mail/templates/sample_text.vis');
  77. $template .= file_get_contents( APP_DIR.'/app/mail/templates/mail_footer.vis');
  78. $template .= '<div style="display:none">'.rand(5, 999).'</div>';
  79. $this->template = $template;
  80. }
  81.  
  82. public function liveSmtp( )
  83. {
  84. $this->mail->isSMTP();
  85. /* $this->mail->SMTPDebug = 2;
  86. $this->mail->Debugoutput = 'html'; */
  87. $this->mail->Host = 'smtp-mail.outlook.com';
  88. $this->mail->Port = 587;
  89. $this->mail->SMTPSecure = 'tls';
  90. $this->mail->SMTPAuth = true;
  91. $this->mail->Username = "yourmail@outlook.com";
  92. $this->mail->Password = "password";
  93. }
  94.  
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement