Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- $mail = new Mail;
- $mail->liveSmtp();
- $mail->template( $templt );
- $mail->send( array( 'to' => 'someone@mail.com' ) );
- */
- class Mail
- {
- private $template ;
- private $mail ;
- function __construct( )
- {
- $this->template = '';
- $this->mail = new PHPMailer( true );
- }
- public function send( array $options = array() )
- {
- $this->liveSmtp();
- $options = array_merge(array(
- 'to' => '',
- 'subject' => 'StreamYou',
- 'to_name' => '',
- 'from' => "streamyoutested@outlook.com",
- // 'from' => EMAIL,
- 'from_name' => '',
- 'body' => $this->template,
- 'alt_body' =>'To view the message, please use an HTML compatible email viewer!',
- 'replay_to' => '',
- 'replay_to_name' => '',
- 'attachments' => array()
- ), $options);
- try {
- $this->mail->AddAddress( $options['to'], $options['to_name']);
- $this->mail->SetFrom( $options['from'], $options['from_name']);
- if($options['replay_to'])
- $this->mail->AddReplyTo($options['replay_to'], $options['replay_to_name']);
- $this->mail->Subject = $options['subject'];
- $this->mail->AltBody = $options['alt_body'];
- // $this->mail->MsgHTML(file_get_contents('contents.html'));
- // $this->mail->MsgHTML( $options['body'] );
- $this->mail->MsgHTML( $options['body'] );
- if(count($options['attachments']))
- foreach ($options['attachments'] as $attachment) {
- $this->mail->AddAttachment( $attachment );
- }
- // $this->mail->AddAttachment('images/phpmailer.gif');
- $this->mail->Send();
- } catch (phpmailerException $e) {
- //echo $e->errorMessage(); //Pretty error messages from PHPMailer
- } catch (Exception $e) {
- // echo $e->getMessage(); //Boring error messages from anything else!
- }
- }
- public function template( $body = '' )
- {
- $template = '';
- $template .= file_get_contents( APP_DIR.'/app/mail/templates/mail_header.vis');
- $template .= $body;
- $template .= file_get_contents( APP_DIR.'/app/mail/templates/sample_text.vis');
- $template .= file_get_contents( APP_DIR.'/app/mail/templates/mail_footer.vis');
- $template .= '<div style="display:none">'.rand(5, 999).'</div>';
- $this->template = $template;
- }
- public function liveSmtp( )
- {
- $this->mail->isSMTP();
- /* $this->mail->SMTPDebug = 2;
- $this->mail->Debugoutput = 'html'; */
- $this->mail->Host = 'smtp-mail.outlook.com';
- $this->mail->Port = 587;
- $this->mail->SMTPSecure = 'tls';
- $this->mail->SMTPAuth = true;
- $this->mail->Username = "yourmail@outlook.com";
- $this->mail->Password = "password";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement