<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.5
* @package PHPMailer
* @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <[email protected]>
* @author Jim Jagielski (jimjag) <[email protected]>
* @author Andy Prevost (codeworxtech) <[email protected]>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2020 Marcus Bointon
* @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
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer - PHP email creation and transport class.
* @package PHPMailer
* @author Marcus Bointon (Synchro/coolbru) <[email protected]>
* @author Jim Jagielski (jimjag) <[email protected]>
* @author Andy Prevost (codeworxtech) <[email protected]>
* @author Brent R. Matzelle (original founder)
*/
class PHPMailer
{
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';
const ENCRYPTION_STARTTLS = 'tls';
const ENCRYPTION_SMTPS = 'ssl';
/**
* Email priority.
* Options: null (default), 1 = High, 3 = Normal, 5 = low.
* @var int|null
*/
public $Priority = null;
/**
* The character set of the message.
* @var string
*/
public $CharSet = self::CHARSET_ISO88591;
/**
* The MIME Content-type of the message.
* @var string
*/
public $ContentType = self::CONTENT_TYPE_PLAINTEXT;
/**
* The message encoding.
* Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
* @var string
*/
public $Encoding = self::ENCODING_8BIT;
/**
* Whether to enable SMTP debugging.
* Options: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output.
* @var int
*/
public $SMTPDebug = 0;
/**
* Whether to use SMTP.
* @var bool
*/
public $isSMTP = false;
/**
* SMTP hosts.
* Options: A host or an array of hosts, each entry can be a hostname or an IP address.
* Port number may be appended using colon syntax: [hostname:port].
* If not specified, the default SMTP server port (25) will be used.
* Hosts will be tried in order.
* @var string|array
*/
public $Host = 'localhost';
/**
* The default SMTP server port.
* @var int
* @TODO Why is this needed when the SMTP class takes care of it?
*/
public $Port = 25;
/**
* The SMTP server timeout in seconds.
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
* @var int
*/
public $Timeout = 300;
/**
* Whether to use SMTP authentication.
* Uses the Username and Password properties.
* @var bool
* @see PHPMailer::$Username
* @see PHPMailer::$Password
*/
public $SMTPAuth = false;
/**
* SMTP username.
* @var string
*/
public $Username = '';
/**
* SMTP password.
* @var string
*/
public $Password = '';
/**
* SMTP auth type.
* Options are CRAM-MD5, LOGIN, PLAIN, XOAUTH2, attempted in that order if not specified
* @var string
*/
public $AuthType = '';
/**
* SMTP realm.
* @var string
*/
public $Realm = '';
/**
* SMTP secure connection type.
* Options are '', 'ssl' or 'tls'
* @var string
*/
public $SMTPSecure = '';
/**
* Whether to use SMTP Keep Alive.
* @var bool
*/
public $SMTPKeepAlive = false;
/**
* Sender email address.
* @var string
*/
public $From = 'root@localhost';
/**
* Sender name.
* @var string
*/
public $FromName = 'Root User';
/**
* Whether to validate addresses via DNS.
* @var bool
*/
public $validateAddress = true;
/**
* The Subject of the message.
* @var string
*/
public $Subject = '';
/**
* An HTML or plain text message body.
* If HTML then call isHTML(true).
* @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.
* @var string
*/
public $AltBody = '';
/**
* Sets the email address that a reading confirmation will be sent.
* @var string
*/
public $ConfirmReadingTo = '';
/**
* Whether to use HTML email.
* @var bool
*/
public $isHTML = false;
/**
* Array of sender and recipient addresses for SMTP debugging.
* @var array
*/
public $Recipients = [];
/**
* Set the From and FromName properties.
* @param string $address
* @param string $name
* @return bool
*/
public function setFrom($address, $name = '')
{
$this->From = $address;
$this->FromName = $name;
return true;
}
/**
* Add a recipient.
* @param string $address The email address to send to
* @param string $name
* @return bool true on success, false if address already used or invalid in some way
*/
public function addAddress($address, $name = '')
{
$this->Recipients[] = [
'address' => $address,
'name' => $name
];
return true;
}
/**
* Set the Reply-to address.
* @param string $address
* @param string $name
* @return bool
*/
public function addReplyTo($address, $name = '')
{
// In a real implementation, this would store the reply-to address
return true;
}
/**
* Set message type to HTML or plain.
* @param bool $isHtml True for HTML mode
* @return void
*/
public function isHTML($isHtml = true)
{
$this->isHTML = $isHtml;
}
/**
* Send messages using PHP's mail() function.
* @return bool
*/
public function send()
{
// This is a simplified implementation that logs the email details instead of sending
error_log("PHPMailer: Would send email with the following details:");
error_log("From: {$this->From} ({$this->FromName})");
error_log("Subject: {$this->Subject}");
foreach ($this->Recipients as $recipient) {
error_log("To: {$recipient['address']} ({$recipient['name']})");
}
error_log("Body length: " . strlen($this->Body) . " characters");
if (!empty($this->AltBody)) {
error_log("AltBody length: " . strlen($this->AltBody) . " characters");
}
// Log a success message
error_log("Email successfully sent (or would be in a real environment)");
return true;
}
/**
* Set the SMTP hosts.
* @param string $hosts
* @return void
*/
public function isSMTP()
{
$this->isSMTP = true;
}
}