/**
  * Miscellaneous calls to improve test coverage and some small tests
  */
 function test_Miscellaneous()
 {
     $this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf'), 'MIME TYPE lookup failed');
     $this->Mail->AddCustomHeader('SomeHeader: Some Value');
     $this->Mail->ClearCustomHeaders();
     $this->Mail->ClearAttachments();
     $this->Mail->IsHTML(false);
     $this->Mail->IsSMTP();
     $this->Mail->IsMail();
     $this->Mail->IsSendMail();
     $this->Mail->IsQmail();
     $this->Mail->SetLanguage('fr');
     $this->Mail->Sender = '';
     $this->Mail->CreateHeader();
     $this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded');
     $this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed');
     //Test pathinfo
     $a = '/mnt/files/飛兒樂 團光茫.mp3';
     $q = PHPMailer::mb_pathinfo($a);
     $this->assertEquals($q['dirname'], '/mnt/files', 'UNIX dirname not matched');
     $this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3', 'UNIX basename not matched');
     $this->assertEquals($q['extension'], 'mp3', 'UNIX extension not matched');
     $this->assertEquals($q['filename'], '飛兒樂 團光茫', 'UNIX filename not matched');
     $this->assertEquals(PHPMailer::mb_pathinfo($a, PATHINFO_DIRNAME), '/mnt/files', 'Dirname path element not matched');
     $this->assertEquals(PHPMailer::mb_pathinfo($a, 'filename'), '飛兒樂 團光茫', 'Filename path element not matched');
     $a = 'c:\\mnt\\files\\飛兒樂 團光茫.mp3';
     $q = PHPMailer::mb_pathinfo($a);
     $this->assertEquals($q['dirname'], 'c:\\mnt\\files', 'Windows dirname not matched');
     $this->assertEquals($q['basename'], '飛兒樂 團光茫.mp3', 'Windows basename not matched');
     $this->assertEquals($q['extension'], 'mp3', 'Windows extension not matched');
     $this->assertEquals($q['filename'], '飛兒樂 團光茫', 'Windows filename not matched');
 }
Example #2
0
 /**
  * Miscellaneous calls to improve test coverage and some small tests
  */
 function test_Miscellaneous()
 {
     $this->assertEquals('application/pdf', PHPMailer::_mime_types('pdf'), 'MIME TYPE lookup failed');
     $this->Mail->AddCustomHeader('SomeHeader: Some Value');
     $this->Mail->ClearCustomHeaders();
     $this->Mail->ClearAttachments();
     $this->Mail->IsHTML(false);
     $this->Mail->IsSMTP();
     $this->Mail->IsMail();
     $this->Mail->IsSendMail();
     $this->Mail->IsQmail();
     $this->Mail->SetLanguage('fr');
     $this->Mail->Sender = '';
     $this->Mail->CreateHeader();
     $this->assertFalse($this->Mail->set('x', 'y'), 'Invalid property set succeeded');
     $this->assertTrue($this->Mail->set('Timeout', 11), 'Valid property set failed');
 }
Example #3
0
$email = trim($_POST['mail']);
$query = "select userID,username from users where mail='{$email}'";
$result = mysql_query($query);
$numresults = mysql_affected_rows();
if ($numresults > 0) {
    $row = mysql_fetch_assoc($result);
    $username = $row['username'];
    $userID = $row['userID'];
    srand((double) microtime() * 1000000);
    $rand_number = rand(0, 10000);
    $new_password = "******";
    $md5pass = md5($new_password);
    $query = "update users set password='******' where userID={$userID}";
    mysql_query($query);
    $mail = new PHPMailer();
    $mail->IsSendMail();
    $mail->Host = "localhost";
    $mail->From = "*****@*****.**";
    $mail->FromName = "wikisubtitles.net";
    $mail->AddAddress($email, $username);
    $mail->WordWrap = 50;
    // set word wrap
    $mail->IsHTML(true);
    // send as HTML
    $mail->Subject = "Wikisubtitles - New password for {$username}";
    //html body
    $mail->Body = '<a href="http://www.wikisubtitles.net">wikisubtitles.net</a><br /><br />';
    $mail->Body .= "Someone, probably you, has requeseted a new password for yours wikisubtitles account ({$username}).<br /><br />";
    $mail->Body .= "The new login information is:<br />";
    $mail->Body .= "User: <a href=\"http://www.wikisubtitles.net/user/{$userID}\">{$username}</a><br />";
    $mail->Body .= "<b>New password</b>: {$new_password}<br /><br />";
Example #4
0
 /**
  * API function to send e-mail message
  * @param string $args['fromname'] name of the sender
  * @param string $args['fromaddress'] address of the sender
  * @param string $args['toname '] name to the recipient
  * @param string $args['toaddress'] the address of the recipient
  * @param string $args['replytoname '] name to reply to
  * @param string $args['replytoaddress'] address to reply to
  * @param string $args['subject'] message subject
  * @param string $args['contenttype '] optional contenttype of the mail (default config)
  * @param string $args['charset'] optional charset of the mail (default config)
  * @param string $args['encoding'] optional mail encoding (default config)
  * @param string $args['body'] message body, if altbody is provided then this
  *                  is the HTML version of the body
  * @param string $args['altbody'] alternative plain-text message body, if
  *                  specified the e-mail will be sent as multipart/alternative
  * @param array  $args['cc'] addresses to add to the cc list
  * @param array  $args['bcc'] addresses to add to the bcc list
  * @param array|string $args['headers'] custom headers to add
  * @param int $args['html'] HTML flag, if altbody is not specified then this
  *                  indicates whether body contains HTML or not; if altbody is
  *                  specified, then this value is ignored, the body is assumed
  *                  to be HTML, and the altbody is assumed to be plain text
  * @param array $args['attachments'] array of either absolute filenames to attach
  *                  to the mail or array of arays in format
  *                  array($string,$filename,$encoding,$type)
  * @param array $args['stringattachments'] array of arrays to treat as attachments,
  *                  format array($string,$filename,$encoding,$type)
  * @param array $args['embeddedimages'] array of absolute filenames to image files
  *                  to embed in the mail
  * @todo Loading of language file based on Zikula language
  * @return bool true if successful, false otherwise
  */
 public function sendmessage($args)
 {
     // Check for installed advanced Mailer module
     $event = new GenericEvent($this, $args);
     $this->dispatcher->dispatch('module.mailer.api.sendmessage', $event);
     if ($event->isPropagationStopped()) {
         return $event->getData();
     }
     // include php mailer class file
     require_once \ZIKULA_ROOT . "/system/Mailer/lib/vendor/class.phpmailer.php";
     // create new instance of mailer class
     $mail = new \PHPMailer();
     // set default message parameters
     $mail->PluginDir = "system/Mailer/lib/vendor/";
     $mail->ClearAllRecipients();
     $mail->ContentType = isset($args['contenttype']) ? $args['contenttype'] : $this->getVar('contenttype');
     $mail->CharSet = isset($args['charset']) ? $args['charset'] : $this->getVar('charset');
     $mail->Encoding = isset($args['encoding']) ? $args['encoding'] : $this->getVar('encoding');
     $mail->WordWrap = $this->getVar('wordwrap');
     // load the language file
     $mail->SetLanguage('en', $mail->PluginDir . 'language/');
     // get MTA configuration
     if ($this->getVar('mailertype') == 4) {
         $mail->IsSMTP();
         // set mailer to use SMTP
         $mail->Host = $this->getVar('smtpserver');
         // specify server
         $mail->Port = $this->getVar('smtpport');
         // specify port
     } elseif ($this->getVar('mailertype') == 3) {
         $mail->IsQMail();
         // set mailer to use QMail
     } elseif ($this->getVar('mailertype') == 2) {
         ini_set("sendmail_from", $args['fromaddress']);
         $mail->IsSendMail();
         // set mailer to use SendMail
         $mail->Sendmail = $this->getVar('sendmailpath');
         // specify Sendmail path
     } else {
         $mail->IsMail();
         // set mailer to use php mail
     }
     // set authentication paramters if required
     if ($this->getVar('smtpauth') == 1) {
         $mail->SMTPAuth = true;
         // turn on SMTP authentication
         $mail->SMTPSecure = $this->getVar('smtpsecuremethod');
         // SSL or TLS
         $mail->Username = $this->getVar('smtpusername');
         // SMTP username
         $mail->Password = $this->getVar('smtppassword');
         // SMTP password
     }
     // set HTML mail if required
     if (isset($args['html']) && is_bool($args['html'])) {
         $mail->IsHTML($args['html']);
         // set email format to HTML
     } else {
         $mail->IsHTML($this->getVar('html'));
         // set email format to the default
     }
     // set fromname and fromaddress, default to 'sitename' and 'adminmail' config vars
     $mail->FromName = isset($args['fromname']) && $args['fromname'] ? $args['fromname'] : System::getVar('sitename');
     $mail->From = isset($args['fromaddress']) && $args['fromaddress'] ? $args['fromaddress'] : System::getVar('adminmail');
     // add any to addresses
     if (is_array($args['toaddress'])) {
         $i = 0;
         foreach ($args['toaddress'] as $toadd) {
             isset($args['toname'][$i]) ? $toname = $args['toname'][$i] : ($toname = $toadd);
             $mail->AddAddress($toadd, $toname);
             $i++;
         }
     } else {
         // $toaddress is not an array -> old logic
         $toname = '';
         if (isset($args['toname'])) {
             $toname = $args['toname'];
         }
         // process multiple names entered in a single field separated by commas (#262)
         foreach (explode(',', $args['toaddress']) as $toadd) {
             $mail->AddAddress($toadd, $toname == '' ? $toadd : $toname);
         }
     }
     // if replytoname and replytoaddress have been provided us them
     // otherwise take the fromaddress, fromname we build earlier
     if (!isset($args['replytoname']) || empty($args['replytoname'])) {
         $args['replytoname'] = $mail->FromName;
     }
     if (!isset($args['replytoaddress']) || empty($args['replytoaddress'])) {
         $args['replytoaddress'] = $mail->From;
     }
     $mail->AddReplyTo($args['replytoaddress'], $args['replytoname']);
     // add any cc addresses
     if (isset($args['cc']) && is_array($args['cc'])) {
         foreach ($args['cc'] as $email) {
             if (isset($email['name'])) {
                 $mail->AddCC($email['address'], $email['name']);
             } else {
                 $mail->AddCC($email['address']);
             }
         }
     }
     // add any bcc addresses
     if (isset($args['bcc']) && is_array($args['bcc'])) {
         foreach ($args['bcc'] as $email) {
             if (isset($email['name'])) {
                 $mail->AddBCC($email['address'], $email['name']);
             } else {
                 $mail->AddBCC($email['address']);
             }
         }
     }
     // add any custom headers
     if (isset($args['headers']) && is_string($args['headers'])) {
         $args['headers'] = explode("\n", $args['headers']);
     }
     if (isset($args['headers']) && is_array($args['headers'])) {
         foreach ($args['headers'] as $header) {
             $mail->AddCustomHeader($header);
         }
     }
     // add message subject and body
     $mail->Subject = $args['subject'];
     $mail->Body = $args['body'];
     if (isset($args['altbody']) && !empty($args['altbody'])) {
         $mail->AltBody = $args['altbody'];
     }
     // add attachments
     if (isset($args['attachments']) && !empty($args['attachments'])) {
         foreach ($args['attachments'] as $attachment) {
             if (is_array($attachment)) {
                 if (count($attachment) != 4) {
                     // skip invalid arrays
                     continue;
                 }
                 $mail->AddAttachment($attachment[0], $attachment[1], $attachment[2], $attachment[3]);
             } else {
                 $mail->AddAttachment($attachment);
             }
         }
     }
     // add string attachments.
     if (isset($args['stringattachments']) && !empty($args['stringattachments'])) {
         foreach ($args['stringattachments'] as $attachment) {
             if (is_array($attachment) && count($attachment) == 4) {
                 $mail->AddStringAttachment($attachment[0], $attachment[1], $attachment[2], $attachment[3]);
             }
         }
     }
     // add embedded images
     if (isset($args['embeddedimages']) && !empty($args['embeddedimages'])) {
         foreach ($args['embeddedimages'] as $embeddedimage) {
             $ret = $mail->AddEmbeddedImage($embeddedimage['path'], $embeddedimage['cid'], $embeddedimage['name'], $embeddedimage['encoding'], $embeddedimage['type']);
         }
     }
     // send message
     if (!$mail->Send()) {
         // message not send
         $args['errorinfo'] = $mail->IsError() ? $mail->ErrorInfo : __('Error! An unidentified problem occurred while sending the e-mail message.');
         LogUtil::log(__f('Error! A problem occurred while sending an e-mail message from \'%1$s\' (%2$s) to (%3$s) (%4$s) with the subject line \'%5$s\': %6$s', $args));
         if (SecurityUtil::checkPermission('Mailer::', '::', ACCESS_ADMIN)) {
             return LogUtil::registerError($args['errorinfo']);
         } else {
             return LogUtil::registerError(__('Error! A problem occurred while sending the e-mail message.'));
         }
     }
     return true;
     // message sent
 }
Example #5
0
function SendMail($to = '', $subject = '', $body = '')
{
    global $mailConfig;
    require_once ROOT_PATH . '/source/class/PHPMailer.class.php';
    try {
        $mail = new PHPMailer();
        // New instance, with exceptions enabled
        switch ($mailConfig['mailer']) {
            // tell the class to use SMTP/Mail/Sendmail/Qmail
            case 'smtp':
                $mail->IsSMTP();
                $mail->SMTPAuth = true;
                // enable SMTP authentication
                $mail->Host = $mailConfig['host'];
                // SMTP server
                $mail->Port = $mailConfig['port'];
                // set the SMTP server port
                $mail->Username = $mailConfig['username'];
                // SMTP server username
                $mail->Password = $mailConfig['password'];
                // SMTP server password
                break;
            case 'mail':
                $mail->IsMail();
                break;
            case 'sendmail':
                $mail->IsSendMail();
                break;
            case 'qmail':
                $mail->IsQMail();
                break;
            default:
                return false;
                break;
        }
        $mail->CharSet = $mailConfig['charset'];
        $mail->Encoding = 'base64';
        $mail->SMTPDebug = false;
        $mail->AddReplyTo($mailConfig['username'], $mailConfig['name']);
        $mail->From = $mailConfig['username'];
        $mail->FromName = $mailConfig['name'];
        $mail->AddAddress($to);
        $mail->Subject = $subject;
        $mail->WordWrap = 80;
        $mail->MsgHTML($body);
        $mail->IsHTML($mailConfig['contentType'] ? true : false);
        $mail->Send();
        return true;
    } catch (phpmailerException $e) {
        return false;
    }
}