コード例 #1
0
 /**
  * Add recipients to the email.
  *
  * @param   mixed   $recipient  Either a string or array of strings [email address(es)]
  * @param   mixed   $name       Either a string or array of strings [name(s)]
  * @param   string  $method     The parent method's name.
  *
  * @return  Mail  Returns this object for chaining.
  *
  * @since   11.1
  */
 protected function add($recipient, $name = '', $method = 'AddAddress')
 {
     // If the recipient is an array, add each recipient... otherwise just add the one
     if (is_array($recipient)) {
         if (is_array($name)) {
             $combined = array_combine($recipient, $name);
             if ($combined === false) {
                 throw new InvalidArgumentException("The number of elements for each array isn't equal.");
             }
             foreach ($combined as $recipientEmail => $recipientName) {
                 $recipientEmail = Helper::cleanLine($recipientEmail);
                 $recipientName = Helper::cleanLine($recipientName);
                 call_user_func('parent::' . $method, $recipientEmail, $recipientName);
             }
         } else {
             $name = Helper::cleanLine($name);
             foreach ($recipient as $to) {
                 $to = Helper::cleanLine($to);
                 call_user_func('parent::' . $method, $to, $name);
             }
         }
     } else {
         $recipient = Helper::cleanLine($recipient);
         call_user_func('parent::' . $method, $recipient, $name);
     }
     return $this;
 }
コード例 #2
0
 /**
  * Create a mailer object
  *
  * @return  Mail object
  *
  * @see     Mail
  * @since   11.1
  */
 protected static function createMailer()
 {
     $conf = self::getConfig();
     $smtpauth = $conf->get('smtpauth') == 0 ? null : 1;
     $smtpuser = $conf->get('smtpuser');
     $smtppass = $conf->get('smtppass');
     $smtphost = $conf->get('smtphost');
     $smtpsecure = $conf->get('smtpsecure');
     $smtpport = $conf->get('smtpport');
     $mailfrom = $conf->get('mailfrom');
     $fromname = $conf->get('fromname');
     $mailer = $conf->get('mailer');
     // Create a JMail object
     $mail = Mail::getInstance();
     // Set default sender without Reply-to
     $mail->SetFrom(MailHelper::cleanLine($mailfrom), MailHelper::cleanLine($fromname), 0);
     // Default mailer is to use PHP's mail function
     switch ($mailer) {
         case 'smtp':
             $mail->useSMTP($smtpauth, $smtphost, $smtpuser, $smtppass, $smtpsecure, $smtpport);
             break;
         case 'sendmail':
             $mail->IsSendmail();
             break;
         default:
             $mail->IsMail();
             break;
     }
     return $mail;
 }