Back to Mail class

Method sendMail

public bool
sendMail
(mixed $from, mixed $fromName, mixed $recipient, mixed $subject, mixed $body, mixed $mode = false, mixed $cc = null, mixed $bcc = null, mixed $attachment = null, mixed $replyTo = null, mixed $replyToName = null)
Function to send an email
Parameters
  • string $from From email address
  • string $fromName From name
  • mixed $recipient Recipient email address(es)
  • string $subject email subject
  • string $body Message body
  • bool $mode false = plain text, true = HTML
  • mixed $cc CC email address(es)
  • mixed $bcc BCC email address(es)
  • mixed $attachment Attachment file name(s)
  • mixed $replyTo Reply to email address(es)
  • mixed $replyToName Reply to name(s)
Returns
  • bool True on success, false on failure when exception throwing is disabled.
Since
  • 1.7.0
-
  • \Joomla\CMS\Mail\Exception\MailDisabledException if the mail function is disabled
  • \PHPMailer\PHPMailer\Exception if exception throwing is enabled
Class: Mail
Project: Joomla

Method sendMail - Source code

/**
 * 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, false on failure when exception throwing is disabled.
 *
 * @since   1.7.0
 *
 * @throws  MailDisabledException  if the mail function is disabled
 * @throws  phpmailerException     if exception throwing is enabled
 */
public function sendMail($from, $fromName, $recipient, $subject, $body, $mode = false, $cc = null, $bcc = null, $attachment = null, $replyTo = null, $replyToName = null)
{
    // Create config object
    $app = Factory::getApplication();
    $this->setSubject($subject);
    $this->setBody($body);
    // Are we sending the email as HTML?
    $this->isHtml($mode);
    /*
     * Do not send the message if adding any of the below items fails
     */
    if ($this->addRecipient($recipient) === false) {
        return false;
    }
    if ($this->addCc($cc) === false) {
        return false;
    }
    if ($this->addBcc($bcc) === false) {
        return false;
    }
    if ($this->addAttachment($attachment) === false) {
        return false;
    }
    // Take care of reply email addresses
    if (\is_array($replyTo)) {
        $numReplyTo = \count($replyTo);
        for ($i = 0; $i < $numReplyTo; $i++) {
            if ($this->addReplyTo($replyTo[$i], $replyToName[$i]) === false) {
                return false;
            }
        }
    } elseif (isset($replyTo)) {
        if ($this->addReplyTo($replyTo, $replyToName) === false) {
            return false;
        }
    } elseif ($app->get('replyto')) {
        $this->addReplyTo($app->get('replyto'), $app->get('replytoname'));
    }
    // Add sender to replyTo only if no replyTo received
    $autoReplyTo = empty($this->ReplyTo);
    if ($this->setSender(array($from, $fromName, $autoReplyTo)) === false) {
        return false;
    }
    return $this->Send();
}