Skip to content

Instantly share code, notes, and snippets.

@vishnukumarpv
Last active December 17, 2016 11:27
Show Gist options
  • Save vishnukumarpv/b8c5f7b3ad9e759362e7130fcb47970b to your computer and use it in GitHub Desktop.
Save vishnukumarpv/b8c5f7b3ad9e759362e7130fcb47970b to your computer and use it in GitHub Desktop.
live (hotmail) smtp for php_mailer
<?php
/**
**
** $mail = new Mail;
** $mail->liveSmtp();
** $mail->template( $templt );
** $mail->send( array( 'to' => '[email protected]' ) );
*/
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' => "[email protected]",
// '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 = "[email protected]";
$this->mail->Password = "password";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment