PHPMailer Pro properties and methods are not compatible with PHPMailer. I have taken the opportunity with this renewed build to name properties more task appropriate. For example, PHPMailer used “From” for the Sender’s email address and “FromName” for the Sender’s name. Those properties are now more appropriately named “SenderEmail” and “SenderName”. "Sender" impacts more than just "From:". It also populates Return-Path, Reply-To, and is the default for Confirming. Those are just two examples, there are more.
I did want to maintain compatibility however. To that end, I have written a small extension to show how PHPMailer Pro can be a direct drop-in replacement, and still use the same code. Here is that extension:
<?php
include(ltrim(str_replace(getcwd(),'',__DIR__),'/') . "/PHPMailer Pro.php");
class_alias('codeworxtech\PHPMailer Pro\PHPMailer Pro','PHPMailer Pro');
class PHPMailer extends PHPMailer Pro {
/* properties */
public $AltBody = '';
public $AuthType = '';
public $Body = '';
public $ConfirmReadingTo = '';
public $do_verp = '';
public $From = '';
public $Fromname = '';
public $Host = '';
public $Hostname = '';
public $LE = '';
public $Mailer = 'smtp';
public $Port = '';
public $Sendmail = '';
public $SMTPAuth = '';
public $SMTPAutoTLS = '';
public $SMTPDebug = '';
public $SMTPKeepAlive = '';
public $SMTPOptions = '';
public $SMTPSecure = '';
public $Username = '';
public $Password = '';
public $SingleTo = '';
public $Timeout = '';
public $UseSendmailOptions = '';
public $deprecated = '';
/* methods */
public function addAddress($val1,$val2='') {
if (trim($val1) != '') {
PHPMailer Pro::AddRecipient([$val1=>$val2]);
}
}
public function addBCC($val1,$val2='') {
if (trim($val1) != '') {
PHPMailer Pro::AddBCC([$val1=>$val2]);
}
}
public function addCC($val1,$val2='') {
if (trim($val1) != '') {
PHPMailer Pro::AddCC([$val1=>$val2]);
}
}
public function isHTML($val) {
$this->SetTypeHTML($val1);
}
public function isMail() {
// deprecated
}
public function isQmail() {
// deprecated in a future release of PHPMailer Pro
$this->Mailer = "sendmail";
}
public function isSendmail() {
// deprecated in a future release of PHPMailer Pro
$this->Mailer = "sendmail";
}
public function isSMTP() {
// deprecated in a future release of PHPMailer Pro
$this->Mailer = "smtp";
}
public function MsgHTML($val,$val2='',$adv=false) {
$this->setCompatible("MessageHTML",$val);
}
public function setFrom($val1,$val2='') {
if (trim($val1) != '') {
PHPMailer Pro::SetSender([$val1=>$val2]);
}
}
public function addReplyTo($val1,$val2='') {
if (trim($val1) != '') {
PHPMailer Pro::AddReplyTo([$val1=>$val2]);
}
}
public function send() {
// do the properties settings - then Send thru PHPMailer Pro
$this->deprecated = $this->AuthType;
$this->deprecated = $this->LE;
$this->deprecated = $this->SMTPAuth;
$this->deprecated = $this->SMTPAutoTLS;
$this->deprecated = $this->SMTPKeepAlive;
$this->deprecated = $this->SMTPSecure;
$this->deprecated = $this->Timeout;
$this->deprecated = $this->UseSendmailOptions;
$this->MessageHTML = $this->Body;
$this->MessageText = $this->AltBody;
$this->SendIndividualEmails = $this->SingleTo;
$this->SendmailServerPath = $this->Sendmail;
$this->SMTP_Debug = $this->SMTPDebug;
$this->SMTP_Host = $this->Host;
$this->SMTP_Options = $this->SMTPOptions;
$this->SMTP_Password = $this->Password;
$this->SMTP_Port = $this->Port;
$this->SMTP_Username = $this->Username;
$this->SMTP_Useverp = $this->do_verp;
$this->Transport = $this->Mailer;
if (PHPMailer Pro::Send()) {
return true;
}
}
public function setCompatible($name, $value = '') {
if (isset($this->name) ) {
$this->name = $value;
}
}
}
?>
Next comes your script that would call this extension. Here is an example of that:
<?php
require("mailer/_plugins/phpmailer.inc.php");
// Instantiate new class
$mail = new cPHPMailer;
// Now you only need to add the necessary stuff
$mail->SetFrom("from@email.com","Joe Smith");
$mail->addReplyTo("from@email.com","Joe Smith");
$mail->isSendmail();
//$mail->isSMTP(); // would send unauthenticated
$mail->AddAddress("josh@site.com", "Josh Adams");
$mail->Subject = "Here is the subject";
$mail->AltBody = "plain text";
$mail->Body = "<p>HTML text</p>";
$mail->AddAttachment(__DIR__ . "/a_jpeg_image.jpg");
if(!$mail->Send()) {
echo "There was an error sending the message";
exit;
} else {
echo "Message was sent successfully";
}
?>
The above script calls the extension ... and full compatiblity.