Source for file mail.php
Documentation is available at mail.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Email Class. Provides a common interface to send email from the Joomla! Platform
* @package Joomla.Platform
* @var array JMail instances container.
protected static $instances =
array();
* @var string Charset of the message.
// PHPMailer has an issue using the relative path for its language files
* Returns the global email object, only creating it
* if it doesn't already exist.
* NOTE: If you need an instance to use that does not have the global configuration
* values, use an id string that is not 'Joomla'.
* @param string $id The id string for the JMail instance [optional]
* @return JMail The global JMail object
if (empty(self::$instances[$id]))
self::$instances[$id] =
new JMail;
return self::$instances[$id];
* @return mixed True if successful; JError if using legacy tree (no exception thrown in that case).
* @throws RuntimeException
if (JFactory::getConfig()->get('mailonline'))
throw
new RuntimeException(sprintf('%s::Send mail not enabled.', get_class($this)));
@$result =
parent::Send();
* @param mixed $from email address and Name of sender
* <code>array([0] => email Address, [1] => Name)</code>
* @return JMail Returns this object for chaining.
* @throws UnexpectedValueException
// If $from is an array we assume it has an address and a name
// If it is an array with entries, use them
// If it is a string we assume it is just the address
// If it is neither, we log a message and throw an exception
throw
new UnexpectedValueException(sprintf('Invalid email Sender: %s, JMail::setSender(%s)', $from));
* @param string $subject Subject of the email
* @return JMail Returns this object for chaining.
* @param string $content Body of the email
* @return JMail Returns this object for chaining.
* 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 JMail Returns this object for chaining.
* @throws InvalidArgumentException
protected function add($recipient, $name =
'', $method =
'AddAddress')
// If the recipient is an array, add each recipient... otherwise just add the one
throw
new InvalidArgumentException("The number of elements for each array isn't equal.");
foreach ($combined as $recipientEmail =>
$recipientName)
call_user_func('parent::' .
$method, $recipientEmail, $recipientName);
foreach ($recipient as $to)
* 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)]
* @return JMail Returns this object for chaining.
$this->add($recipient, $name, 'AddAddress');
* Add carbon copy recipients to the email
* @param mixed $cc Either a string or array of strings [email address(es)]
* @param mixed $name Either a string or array of strings [name(s)]
* @return JMail Returns this object for chaining.
public function addCC($cc, $name =
'')
// If the carbon copy recipient is an array, add each recipient... otherwise just add the one
$this->add($cc, $name, 'AddCC');
* Add blind carbon copy recipients to the email
* @param mixed $bcc Either a string or array of strings [email address(es)]
* @param mixed $name Either a string or array of strings [name(s)]
* @return JMail Returns this object for chaining.
public function addBCC($bcc, $name =
'')
// If the blind carbon copy recipient is an array, add each recipient... otherwise just add the one
$this->add($bcc, $name, 'AddBCC');
* Add file attachments to the email
* @param mixed $attachment Either a string or array of strings [filenames]
* @param mixed $name Either a string or array of strings [names]
* @param mixed $encoding The encoding of the attachment
* @param mixed $type The mime type
* @return JMail Returns this object for chaining.
* @throws InvalidArgumentException
public function addAttachment($attachment, $name =
'', $encoding =
'base64', $type =
'application/octet-stream')
// If the file attachments is an array, add each file... otherwise just add the one
if (!empty($name) &&
count($attachment) !=
count($name))
throw
new InvalidArgumentException("The number of attachments must be equal with the number of name");
foreach ($attachment as $key =>
$file)
* Add Reply to email address(es) to the email
* @param mixed $replyto Either a string or array of strings [email address(es)]
* @param mixed $name Either a string or array of strings [name(s)]
* @return JMail Returns this object for chaining.
$this->add($replyto, $name, 'AddReplyTo');
* Sets message type to HTML
* @param boolean $ishtml Boolean true or false.
* @return JMail Returns this object for chaining.
public function isHtml($ishtml =
true)
* Use sendmail for sending the email
* @param string $sendmail Path to sendmail [optional]
* @return boolean True on success
* Use SMTP for sending the email
* @param string $auth SMTP Authentication [optional]
* @param string $host SMTP Host [optional]
* @param string $user SMTP Username [optional]
* @param string $pass SMTP Password [optional]
* @param string $secure Use secure methods
* @param integer $port The SMTP port
* @return boolean True on success
public function useSMTP($auth =
null, $host =
null, $user =
null, $pass =
null, $secure =
null, $port =
25)
if ($secure ==
'ssl' ||
$secure ==
'tls')
* Function to send an email
* @param string $from From email address
* @param string $fromName From name
* @param mixed $recipient Recipient email address(es)
* @param string $subject email subject
* @param string $body Message body
* @param boolean $mode false = plain text, true = HTML
* @param mixed $cc CC email address(es)
* @param mixed $bcc BCC email address(es)
* @param mixed $attachment Attachment file name(s)
* @param mixed $replyTo Reply to email address(es)
* @param mixed $replyToName Reply to name(s)
* @return boolean True on success
public function sendMail($from, $fromName, $recipient, $subject, $body, $mode =
false, $cc =
null, $bcc =
null, $attachment =
null,
$replyTo =
null, $replyToName =
null)
// Are we sending the email as HTML?
// Take care of reply email addresses
$numReplyTo =
count($replyTo);
for ($i =
0; $i <
$numReplyTo; $i++
)
$this->addReplyTo(array($replyTo[$i], $replyToName[$i]));
// Add sender to replyTo only if no replyTo received
$autoReplyTo =
(empty($this->ReplyTo)) ?
true :
false;
$this->setSender(array($from, $fromName, $autoReplyTo));
* Sends mail to administrator for approval of a user submission
* @param string $adminName Name of administrator
* @param string $adminEmail Email address of administrator
* @param string $email [NOT USED TODO: Deprecate?]
* @param string $type Type of item to approve
* @param string $title Title of item to approve
* @param string $author Author of item to approve
* @param string $url A URL to included in the mail
* @return boolean True on success
public function sendAdminMail($adminName, $adminEmail, $email, $type, $title, $author, $url =
null)
$subject =
JText::sprintf('JLIB_MAIL_USER_SUBMITTED', $type);
$message =
sprintf(JText::_('JLIB_MAIL_MSG_ADMIN'), $adminName, $type, $title, $author, $url, $url, 'administrator', $type);
$message .=
JText::_('JLIB_MAIL_MSG') .
"\n";
Documentation generated on Tue, 19 Nov 2013 15:07:30 +0100 by phpDocumentor 1.4.3