ZwiiCMS, le gestionnaire de site Web sans base de données à installer. Conçu en 2008 par Rémi Jean, le développement a été repris par Frédéric Tempez en 2018. zwii cms nosql json flat file https://www.zwiicms.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ZwiiCMS/core/class/phpmailer/PHPMailer.class.php

5072 lines
173 KiB

4 years ago
<?php
8 months ago
4 years ago
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.5.
*
3 years ago
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
*
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
8 months ago
* @copyright 2012 - 2020 Marcus Bointon
4 years ago
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
4 years ago
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
4 years ago
/**
* PHPMailer - PHP email creation and transport class.
*
3 years ago
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
4 years ago
*/
class PHPMailer
{
3 years ago
const CHARSET_ASCII = 'us-ascii';
const CHARSET_ISO88591 = 'iso-8859-1';
const CHARSET_UTF8 = 'utf-8';
const CONTENT_TYPE_PLAINTEXT = 'text/plain';
const CONTENT_TYPE_TEXT_CALENDAR = 'text/calendar';
const CONTENT_TYPE_TEXT_HTML = 'text/html';
const CONTENT_TYPE_MULTIPART_ALTERNATIVE = 'multipart/alternative';
const CONTENT_TYPE_MULTIPART_MIXED = 'multipart/mixed';
const CONTENT_TYPE_MULTIPART_RELATED = 'multipart/related';
const ENCODING_7BIT = '7bit';
const ENCODING_8BIT = '8bit';
const ENCODING_BASE64 = 'base64';
const ENCODING_BINARY = 'binary';
const ENCODING_QUOTED_PRINTABLE = 'quoted-printable';
4 years ago
3 years ago
const ENCRYPTION_STARTTLS = 'tls';
const ENCRYPTION_SMTPS = 'ssl';
const ICAL_METHOD_REQUEST = 'REQUEST';
const ICAL_METHOD_PUBLISH = 'PUBLISH';
const ICAL_METHOD_REPLY = 'REPLY';
const ICAL_METHOD_ADD = 'ADD';
const ICAL_METHOD_CANCEL = 'CANCEL';
const ICAL_METHOD_REFRESH = 'REFRESH';
const ICAL_METHOD_COUNTER = 'COUNTER';
const ICAL_METHOD_DECLINECOUNTER = 'DECLINECOUNTER';
4 years ago
/**
* Email priority.
* Options: null (default), 1 = High, 3 = Normal, 5 = low.
* When null, the header is not set at all.
*
3 years ago
* @var int|null
4 years ago
*/
public $Priority;
4 years ago
/**
* The character set of the message.
*
4 years ago
* @var string
*/
public $CharSet = self::CHARSET_ISO88591;
4 years ago
/**
* The MIME Content-type of the message.
*
4 years ago
* @var string
*/
public $ContentType = self::CONTENT_TYPE_PLAINTEXT;
4 years ago
/**
* The message encoding.
* Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
*
4 years ago
* @var string
*/
public $Encoding = self::ENCODING_8BIT;
4 years ago
/**
* Holds the most recent mailer error message.
*
4 years ago
* @var string
*/
public $ErrorInfo = '';
/**
* The From email address for the message.
*
4 years ago
* @var string
*/
8 months ago
public $From = '';
4 years ago
/**
* The From name of the message.
*
4 years ago
* @var string
*/
8 months ago
public $FromName = '';
4 years ago
/**
* The envelope sender of the message.
* This will usually be turned into a Return-Path header by the receiver,
* and is the address that bounces will be sent to.
* If not empty, will be passed via `-f` to sendmail or as the 'MAIL FROM' value over SMTP.
*
4 years ago
* @var string
*/
public $Sender = '';
/**
* The Subject of the message.
*
4 years ago
* @var string
*/
public $Subject = '';
/**
* An HTML or plain text message body.
* If HTML then call isHTML(true).
*
4 years ago
* @var string
*/
public $Body = '';
/**
* The plain-text message body.
* This body can be read by mail clients that do not have HTML email
* capability such as mutt & Eudora.
* Clients that can read HTML will view the normal Body.
*
4 years ago
* @var string
*/
public $AltBody = '';
/**
* An iCal message part body.
* Only supported in simple alt or alt_inline message types
* To generate iCal event structures, use classes like EasyPeasyICS or iCalcreator.
*
* @see http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
* @see http://kigkonsult.se/iCalcreator/
*
4 years ago
* @var string
*/
public $Ical = '';
3 years ago
/**
* Value-array of "method" in Contenttype header "text/calendar"
*
* @var string[]
*/
protected static $IcalMethods = [
self::ICAL_METHOD_REQUEST,
self::ICAL_METHOD_PUBLISH,
self::ICAL_METHOD_REPLY,
self::ICAL_METHOD_ADD,
self::ICAL_METHOD_CANCEL,
self::ICAL_METHOD_REFRESH,
self::ICAL_METHOD_COUNTER,
self::ICAL_METHOD_DECLINECOUNTER,
];
4 years ago
/**
* The complete compiled MIME message body.
*
4 years ago
* @var string
*/
protected $MIMEBody = '';
/**
* The complete compiled MIME message headers.
*
4 years ago
* @var string
*/
protected $MIMEHeader = '';
/**
* Extra headers that createHeader() doesn't fold in.
*
4 years ago
* @var string
*/
protected $mailHeader = '';
/**
* Word-wrap the message body to this number of chars.
* Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
*
* @see static::STD_LINE_LENGTH
*
* @var int
4 years ago
*/
public $WordWrap = 0;
/**
* Which method to use to send mail.
* Options: "mail", "sendmail", or "smtp".
*
4 years ago
* @var string
*/
public $Mailer = 'mail';
/**
* The path to the sendmail program.
*
4 years ago
* @var string
*/
public $Sendmail = '/usr/sbin/sendmail';
/**
* Whether mail() uses a fully sendmail-compatible MTA.
* One which supports sendmail's "-oi -f" options.
*
* @var bool
4 years ago
*/
public $UseSendmailOptions = true;
/**
* The email address that a reading confirmation should be sent to, also known as read receipt.
*
4 years ago
* @var string
*/
public $ConfirmReadingTo = '';
/**
* The hostname to use in the Message-ID header and as default HELO string.
* If empty, PHPMailer attempts to find one with, in order,
* $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value
* 'localhost.localdomain'.
*
3 years ago
* @see PHPMailer::$Helo
*
4 years ago
* @var string
*/
public $Hostname = '';
/**
* An ID to be used in the Message-ID header.
* If empty, a unique id will be generated.
* You can set your own, but it must be in the format "<id@domain>",
* as defined in RFC5322 section 3.6.4 or it will be ignored.
*
4 years ago
* @see https://tools.ietf.org/html/rfc5322#section-3.6.4
*
4 years ago
* @var string
*/
public $MessageID = '';
/**
* The message Date to be used in the Date header.
* If empty, the current date will be added.
*
4 years ago
* @var string
*/
public $MessageDate = '';
/**
* SMTP hosts.
* Either a single hostname or multiple semicolon-delimited hostnames.
* You can also specify a different port
* for each host by using this format: [hostname:port]
* (e.g. "smtp1.example.com:25;smtp2.example.com").
* You can also specify encryption type, for example:
* (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
* Hosts will be tried in order.
*
4 years ago
* @var string
*/
public $Host = 'localhost';
/**
* The default SMTP server port.
*
* @var int
4 years ago
*/
public $Port = 25;
/**
3 years ago
* The SMTP HELO/EHLO name used for the SMTP connection.
4 years ago
* Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find
* one with the same method described above for $Hostname.
*
4 years ago
* @see PHPMailer::$Hostname
*
* @var string
4 years ago
*/
public $Helo = '';
/**
* What kind of encryption to use on the SMTP connection.
3 years ago
* Options: '', static::ENCRYPTION_STARTTLS, or static::ENCRYPTION_SMTPS.
*
4 years ago
* @var string
*/
public $SMTPSecure = '';
/**
* Whether to enable TLS encryption automatically if a server supports it,
* even if `SMTPSecure` is not set to 'tls'.
* Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
*
* @var bool
4 years ago
*/
public $SMTPAutoTLS = true;
/**
* Whether to use SMTP authentication.
* Uses the Username and Password properties.
*
4 years ago
* @see PHPMailer::$Username
* @see PHPMailer::$Password
*
* @var bool
4 years ago
*/
public $SMTPAuth = false;
/**
* Options array passed to stream_context_create when connecting via SMTP.
*
4 years ago
* @var array
*/
public $SMTPOptions = [];
4 years ago
/**
* SMTP username.
*
4 years ago
* @var string
*/
public $Username = '';
/**
* SMTP password.
*
4 years ago
* @var string
*/
public $Password = '';
/**
* SMTP auth type.
* Options are CRAM-MD5, LOGIN, PLAIN, XOAUTH2, attempted in that order if not specified.
*
4 years ago
* @var string
*/
public $AuthType = '';
/**
8 months ago
* An implementation of the PHPMailer OAuthTokenProvider interface.
*
8 months ago
* @var OAuthTokenProvider
4 years ago
*/
protected $oauth;
4 years ago
/**
* The SMTP server timeout in seconds.
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2.
*
* @var int
4 years ago
*/
public $Timeout = 300;
/**
* Comma separated list of DSN notifications
* 'NEVER' under no circumstances a DSN must be returned to the sender.
* If you use NEVER all other notifications will be ignored.
* 'SUCCESS' will notify you when your mail has arrived at its destination.
* 'FAILURE' will arrive if an error occurred during delivery.
* 'DELAY' will notify you if there is an unusual delay in delivery, but the actual
* delivery's outcome (success or failure) is not yet decided.
*
* @see https://tools.ietf.org/html/rfc3461 See section 4.1 for more information about NOTIFY
*/
public $dsn = '';
4 years ago
/**
* SMTP class debug output mode.
* Debug output level.
* Options:
8 months ago
* @see SMTP::DEBUG_OFF: No output
* @see SMTP::DEBUG_CLIENT: Client messages
* @see SMTP::DEBUG_SERVER: Client and server messages
* @see SMTP::DEBUG_CONNECTION: As SERVER plus connection status
* @see SMTP::DEBUG_LOWLEVEL: Noisy, low-level data output, rarely needed
*
4 years ago
* @see SMTP::$do_debug
*
* @var int
4 years ago
*/
public $SMTPDebug = 0;
/**
* How to handle debug output.
* Options:
* * `echo` Output plain-text as-is, appropriate for CLI
* * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
* * `error_log` Output to error log as configured in php.ini
* By default PHPMailer will use `echo` if run from a `cli` or `cli-server` SAPI, `html` otherwise.
4 years ago
* Alternatively, you can provide a callable expecting two params: a message string and the debug level:
*
* ```php
4 years ago
* $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
* ```
*
* Alternatively, you can pass in an instance of a PSR-3 compatible logger, though only `debug`
* level output is used:
*
* ```php
* $mail->Debugoutput = new myPsr3Logger;
* ```
*
4 years ago
* @see SMTP::$Debugoutput
*
* @var string|callable|\Psr\Log\LoggerInterface
4 years ago
*/
public $Debugoutput = 'echo';
/**
8 months ago
* Whether to keep the SMTP connection open after each message.
* If this is set to true then the connection will remain open after a send,
* and closing the connection will require an explicit call to smtpClose().
* It's a good idea to use this if you are sending multiple messages as it reduces overhead.
* See the mailing list example for how to use it.
*
* @var bool
4 years ago
*/
public $SMTPKeepAlive = false;
/**
* Whether to split multiple to addresses into multiple messages
* or send them all in one message.
* Only supported in `mail` and `sendmail` transports, not in SMTP.
*
* @var bool
8 months ago
*
* @deprecated 6.0.0 PHPMailer isn't a mailing list manager!
4 years ago
*/
public $SingleTo = false;
/**
* Storage for addresses when SingleTo is enabled.
*
4 years ago
* @var array
*/
protected $SingleToArray = [];
4 years ago
/**
* Whether to generate VERP addresses on send.
* Only applicable when sending via SMTP.
*
* @see https://en.wikipedia.org/wiki/Variable_envelope_return_path
* @see http://www.postfix.org/VERP_README.html Postfix VERP info
*
* @var bool
4 years ago
*/
public $do_verp = false;
/**
* Whether to allow sending messages with an empty body.
*
* @var bool
4 years ago
*/
public $AllowEmpty = false;
/**
* DKIM selector.
*
4 years ago
* @var string
*/
public $DKIM_selector = '';
/**
* DKIM Identity.
* Usually the email address used as the source of the email.
*
4 years ago
* @var string
*/
public $DKIM_identity = '';
/**
* DKIM passphrase.
* Used if your key is encrypted.
*
4 years ago
* @var string
*/
public $DKIM_passphrase = '';
/**
* DKIM signing domain name.
*
4 years ago
* @example 'example.com'
*
4 years ago
* @var string
*/
public $DKIM_domain = '';
/**
* DKIM Copy header field values for diagnostic use.
*
* @var bool
*/
public $DKIM_copyHeaderFields = true;
/**
* DKIM Extra signing headers.
*
* @example ['List-Unsubscribe', 'List-Help']
*
* @var array
*/
public $DKIM_extraHeaders = [];
4 years ago
/**
* DKIM private key file path.
*
4 years ago
* @var string
*/
public $DKIM_private = '';
/**
* DKIM private key string.
*
4 years ago
* If set, takes precedence over `$DKIM_private`.
*
4 years ago
* @var string
*/
public $DKIM_private_string = '';
/**
* Callback Action function name.
*
* The function that handles the result of the send email action.
* It is called out by send() for each email sent.
*
* Value can be any php callable: http://www.php.net/is_callable
*
* Parameters:
* bool $result result of the send action
4 years ago
* array $to email addresses of the recipients
* array $cc cc email addresses
* array $bcc bcc email addresses
* string $subject the subject
* string $body the email body
* string $from email address of sender
* string $extra extra information of possible use
* "smtp_transaction_id' => last smtp transaction id
*
4 years ago
* @var string
*/
public $action_function = '';
/**
* What to put in the X-Mailer header.
3 years ago
* Options: An empty string for PHPMailer default, whitespace/null for none, or a string to use.
*
3 years ago
* @var string|null
4 years ago
*/
public $XMailer = '';
/**
* Which validator to use by default when validating email addresses.
* May be a callable to inject your own validator, but there are several built-in validators.
* The default validator uses PHP's FILTER_VALIDATE_EMAIL filter_var option.
*
4 years ago
* @see PHPMailer::validateAddress()
*
4 years ago
* @var string|callable
*/
public static $validator = 'php';
4 years ago
/**
* An instance of the SMTP sender class.
*
4 years ago
* @var SMTP
*/
protected $smtp;
4 years ago
/**
* The array of 'to' names and addresses.
*
4 years ago
* @var array
*/
protected $to = [];
4 years ago
/**
* The array of 'cc' names and addresses.
*
4 years ago
* @var array
*/
protected $cc = [];
4 years ago
/**
* The array of 'bcc' names and addresses.
*
4 years ago
* @var array
*/
protected $bcc = [];
4 years ago
/**
* The array of reply-to names and addresses.
*
4 years ago
* @var array
*/
protected $ReplyTo = [];
4 years ago
/**
* An array of all kinds of addresses.
* Includes all of $to, $cc, $bcc.
*
* @see PHPMailer::$to
* @see PHPMailer::$cc
* @see PHPMailer::$bcc
*
4 years ago
* @var array
*/
protected $all_recipients = [];
4 years ago
/**
* An array of names and addresses queued for validation.
* In send(), valid and non duplicate entries are moved to $all_recipients
* and one of $to, $cc, or $bcc.
* This array is used only for addresses with IDN.
*
* @see PHPMailer::$to
* @see PHPMailer::$cc
* @see PHPMailer::$bcc
4 years ago
* @see PHPMailer::$all_recipients
*
* @var array
4 years ago
*/
protected $RecipientsQueue = [];
4 years ago
/**
* An array of reply-to names and addresses queued for validation.
* In send(), valid and non duplicate entries are moved to $ReplyTo.
* This array is used only for addresses with IDN.
*
4 years ago
* @see PHPMailer::$ReplyTo
*
* @var array
4 years ago
*/
protected $ReplyToQueue = [];
4 years ago
/**
* The array of attachments.
*
4 years ago
* @var array
*/
protected $attachment = [];
4 years ago
/**
* The array of custom headers.
*
4 years ago
* @var array
*/
protected $CustomHeader = [];
4 years ago
/**
* The most recent Message-ID (including angular brackets).
*
4 years ago
* @var string
*/
protected $lastMessageID = '';
/**
* The message's MIME type.
*
4 years ago
* @var string
*/
protected $message_type = '';
/**
* The array of MIME boundary strings.
*
4 years ago
* @var array
*/
protected $boundary = [];
4 years ago
/**
8 months ago
* The array of available text strings for the current language.
*
4 years ago
* @var array
*/
protected $language = [];
4 years ago
/**
* The number of errors encountered.
*
* @var int
4 years ago
*/
protected $error_count = 0;
/**
* The S/MIME certificate file path.
*
4 years ago
* @var string
*/
protected $sign_cert_file = '';
/**
* The S/MIME key file path.
*
4 years ago
* @var string
*/
protected $sign_key_file = '';
/**
* The optional S/MIME extra certificates ("CA Chain") file path.
*
4 years ago
* @var string
*/
protected $sign_extracerts_file = '';
/**
* The S/MIME password for the key.
* Used only if the key is encrypted.
*
4 years ago
* @var string
*/
protected $sign_key_pass = '';
/**
* Whether to throw exceptions for errors.
*
* @var bool
4 years ago
*/
protected $exceptions = false;
/**
* Unique ID used for message ID and boundaries.
*
4 years ago
* @var string
*/
protected $uniqueid = '';
/**
* The PHPMailer Version number.
*
* @var string
*/
8 months ago
const VERSION = '6.6.0';
4 years ago
/**
* Error severity: message only, continue processing.
*
* @var int
4 years ago
*/
const STOP_MESSAGE = 0;
/**
* Error severity: message, likely ok to continue processing.
*
* @var int
4 years ago
*/
const STOP_CONTINUE = 1;
/**
* Error severity: message, plus full stop, critical error reached.
*
* @var int
4 years ago
*/
const STOP_CRITICAL = 2;
/**
3 years ago
* The SMTP standard CRLF line break.
* If you want to change line break format, change static::$LE, not this.
*/
const CRLF = "\r\n";
/**
* "Folding White Space" a white space string used for line folding.
*/
const FWS = ' ';
/**
* SMTP RFC standard line ending; Carriage Return, Line Feed.
*
* @var string
4 years ago
*/
3 years ago
protected static $LE = self::CRLF;
/**
* The maximum line length supported by mail().
*
* Background: mail() will sometimes corrupt messages
* with headers headers longer than 65 chars, see #818.
*
* @var int
*/
const MAIL_MAX_LINE_LENGTH = 63;
4 years ago
/**
* The maximum line length allowed by RFC 2822 section 2.1.1.
*
* @var int
4 years ago
*/
const MAX_LINE_LENGTH = 998;
/**
* The lower maximum line length allowed by RFC 2822 section 2.1.1.
* This length does NOT include the line break
* 76 means that lines will be 77 or 78 chars depending on whether
* the line break format is LF or CRLF; both are valid.
*
* @var int
*/
const STD_LINE_LENGTH = 76;
4 years ago
/**
* Constructor.
*
* @param bool $exceptions Should we throw external exceptions?
4 years ago
*/
public function __construct($exceptions = null)
{
if (null !== $exceptions) {
$this->exceptions = (bool) $exceptions;
4 years ago
}
//Pick an appropriate debug output format automatically
$this->Debugoutput = (strpos(PHP_SAPI, 'cli') !== false ? 'echo' : 'html');
}
/**
* Destructor.
*/
public function __destruct()
{
//Close any open SMTP connection nicely
$this->smtpClose();
}
/**
* Call mail() in a safe_mode-aware fashion.
* Also, unless sendmail_path points to sendmail (or something that
* claims to be sendmail), don't pass params (not a perfect fix,
* but it will do).
*
* @param string $to To
* @param string $subject Subject
* @param string $body Message Body
* @param string $header Additional Header(s)
* @param string|null $params Params
*
* @return bool
4 years ago
*/
private function mailPassthru($to, $subject, $body, $header, $params)
{
//Check overloading of mail function to avoid double-encoding
if (ini_get('mbstring.func_overload') & 1) {
$subject = $this->secureHeader($subject);
} else {
$subject = $this->encodeHeader($this->secureHeader($subject));
}
//Calling mail() with null params breaks
8 months ago
$this->edebug('Sending with mail()');
$this->edebug('Sendmail path: ' . ini_get('sendmail_path'));
$this->edebug("Envelope sender: {$this->Sender}");
$this->edebug("To: {$to}");
$this->edebug("Subject: {$subject}");
$this->edebug("Headers: {$header}");
3 years ago
if (!$this->UseSendmailOptions || null === $params) {
4 years ago
$result = @mail($to, $subject, $body, $header);
} else {
8 months ago
$this->edebug("Additional params: {$params}");
4 years ago
$result = @mail($to, $subject, $body, $header, $params);
}
8 months ago
$this->edebug('Result: ' . ($result ? 'true' : 'false'));
4 years ago
return $result;
}
4 years ago
/**
8 months ago
* Output debugging info via a user-defined method.
* Only generates output if debug output is enabled.
*
4 years ago
* @see PHPMailer::$Debugoutput
* @see PHPMailer::$SMTPDebug
*
4 years ago
* @param string $str
*/
protected function edebug($str)
{
if ($this->SMTPDebug <= 0) {
return;
}
//Is this a PSR-3 logger?
if ($this->Debugoutput instanceof \Psr\Log\LoggerInterface) {
$this->Debugoutput->debug($str);
return;
}
4 years ago
//Avoid clash with built-in function names
3 years ago
if (is_callable($this->Debugoutput) && !in_array($this->Debugoutput, ['error_log', 'html', 'echo'])) {
4 years ago
call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
4 years ago
return;
}
switch ($this->Debugoutput) {
case 'error_log':
//Don't output, just log
8 months ago
/** @noinspection ForgottenDebugOutputInspection */
4 years ago
error_log($str);
break;
case 'html':
//Cleans up output a bit for a better looking, HTML-safe output
echo htmlentities(
preg_replace('/[\r\n]+/', '', $str),
ENT_QUOTES,
'UTF-8'
), "<br>\n";
4 years ago
break;
case 'echo':
default:
//Normalize line breaks
3 years ago
$str = preg_replace('/\r\n|\r/m', "\n", $str);
echo gmdate('Y-m-d H:i:s'),
"\t",
//Trim trailing space
trim(
3 years ago
//Indent for readability, except for trailing break
str_replace(
"\n",
"\n \t ",
trim($str)
)
),
"\n";
4 years ago
}
}
/**
* Sets message type to HTML or plain.
*
* @param bool $isHtml True for HTML mode
4 years ago
*/
public function isHTML($isHtml = true)
{
if ($isHtml) {
$this->ContentType = static::CONTENT_TYPE_TEXT_HTML;
4 years ago
} else {
$this->ContentType = static::CONTENT_TYPE_PLAINTEXT;
4 years ago
}
}
/**
* Send messages using SMTP.
*/
public function isSMTP()
{
$this->Mailer = 'smtp';
}
/**
* Send messages using PHP's mail() function.
*/
public function isMail()
{
$this->Mailer = 'mail';
}
/**
* Send messages using $Sendmail.
*/
public function isSendmail()
{
$ini_sendmail_path = ini_get('sendmail_path');
if (false === stripos($ini_sendmail_path, 'sendmail')) {
4 years ago
$this->Sendmail = '/usr/sbin/sendmail';
} else {
$this->Sendmail = $ini_sendmail_path;
}
$this->Mailer = 'sendmail';
}
/**
* Send messages using qmail.
*/
public function isQmail()
{
$ini_sendmail_path = ini_get('sendmail_path');
if (false === stripos($ini_sendmail_path, 'qmail')) {
4 years ago
$this->Sendmail = '/var/qmail/bin/qmail-inject';
} else {
$this->Sendmail = $ini_sendmail_path;
}
$this->Mailer = 'qmail';
}
/**
* Add a "To" address.
*
4 years ago
* @param string $address The email address to send to
* @param string $name
*
* @throws Exception
*
* @return bool true on success, false if address already used or invalid in some way
4 years ago
*/
public function addAddress($address, $name = '')
{
return $this->addOrEnqueueAnAddress('to', $address, $name);
}
/**
* Add a "CC" address.
*
4 years ago
* @param string $address The email address to send to
* @param string $name
*
* @throws Exception
*
* @return bool true on success, false if address already used or invalid in some way
4 years ago
*/
public function addCC($address, $name = '')
{
return $this->addOrEnqueueAnAddress('cc', $address, $name);
}
/**
* Add a "BCC" address.
*
4 years ago
* @param string $address The email address to send to
* @param string $name
*
* @throws Exception
*
* @return bool true on success, false if address already used or invalid in some way
4 years ago
*/
public function addBCC($address, $name = '')
{
return $this->addOrEnqueueAnAddress('bcc', $address, $name);
}
/**
* Add a "Reply-To" address.
*
4 years ago
* @param string $address The email address to reply to
* @param string $name
*
* @throws Exception
*
* @return bool true on success, false if address already used or invalid in some way
4 years ago
*/
public function addReplyTo($address, $name = '')
{
return $this->addOrEnqueueAnAddress('Reply-To', $address, $name);
}
/**
* Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer
* can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still
* be modified after calling this function), addition of such addresses is delayed until send().
* Addresses that have been added already return false, but do not throw exceptions.
*
* @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
4 years ago
* @param string $address The email address to send, resp. to reply to
* @param string $name
*
* @throws Exception
*
* @return bool true on success, false if address already used or invalid in some way
4 years ago
*/
protected function addOrEnqueueAnAddress($kind, $address, $name)
{
$address = trim($address);
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
$pos = strrpos($address, '@');
if (false === $pos) {
8 months ago
//At-sign is missing.
$error_message = sprintf(
'%s (%s): %s',
$this->lang('invalid_address'),
$kind,
$address
);
4 years ago
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new Exception($error_message);
4 years ago
}
4 years ago
return false;
}
$params = [$kind, $address, $name];
8 months ago
//Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
3 years ago
if (static::idnSupported() && $this->has8bitChars(substr($address, ++$pos))) {
if ('Reply-To' !== $kind) {
4 years ago
if (!array_key_exists($address, $this->RecipientsQueue)) {