<html>
<head>
<title>PHPMailer - Sendmail advanced test</title>
</head>
<body>

<?php 
require_once '../class.phpmailer-lite.php';
$mail = new PHPMailerLite(true);
// the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSendmail();
// telling the class to use SendMail transport
try {
    $mail->SetFrom('*****@*****.**', 'First Last');
    $mail->AddAddress('*****@*****.**', 'John Doe');
    $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
    $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
    // optional - MsgHTML will create an alternate automatically
    $mail->MsgHTML(file_get_contents('contents.html'));
    $mail->AddAttachment('images/phpmailer.gif');
    // attachment
    $mail->AddAttachment('images/phpmailer_mini.gif');
    // attachment
    $mail->Send();
    echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
    echo $e->errorMessage();
    //Pretty error messages from PHPMailer
} catch (Exception $e) {
    echo $e->getMessage();
    //Boring error messages from anything else!
Beispiel #2
0
 /**
  **  Sends mail for account activation
  **
  **  Selects account record by ID stored in the class from __construct()
  **
  **  Returns:
  **  --------------------------------------------------------------------------------------------
  **  true  - Returned when the mail is successfully sent
  **  false - Returned when the function fails to load mail HTML
  **        - Returned when the accounts query failed
  **        - Returned when the PHPMailer class failed to send mail
  **  --------------------------------------------------------------------------------------------
  **/
 public function sendMail()
 {
     global $config, $DB;
     //setup the PHPMailer class
     $mail = new PHPMailerLite();
     $mail->IsSendmail();
     $mail->SetFrom($config['Email'], 'DuloStore Support');
     //select the account record
     $res = $DB->prepare("SELECT id, email, firstName, lastName FROM `accounts` WHERE `id` = :account LIMIT 1");
     $res->bindParam(':account', $this->account, PDO::PARAM_INT);
     $res->execute();
     if ($res->rowCount() > 0) {
         $row = $res->fetch(PDO::FETCH_ASSOC);
         //get the message html
         $message = file_get_contents($config['RootPath'] . '/activation_mail.html');
         //break if the function failed to laod HTML
         if (!$message) {
             return false;
         }
         //replace the tags with info
         $search = array('{FIRST_NAME}', '{LAST_NAME}', '{URL}');
         $replace = array($row['firstName'], $row['lastName'], $config['BaseURL'] . '/index.php?page=activation&key=' . $this->get_encodedKey());
         $message = str_replace($search, $replace, $message);
         $mail->AddAddress($row['email'], $row['firstName'] . ' ' . $row['lastName']);
         $mail->Subject = 'DuloStore Account Activation';
         $mail->MsgHTML($message);
         if (!$mail->Send()) {
             return false;
         }
     } else {
         return false;
     }
     return true;
 }