I have a question regarding optimizing a php email class. It's basically a wrapper class than needs to be able to accept different objects and always output an email. I'm trying to make it generic, in it's current form it's working but I still feel like it may be to tightly coupled. I was hoping someone here could make some suggestions on how to improve it. I would really appreciate it.
require_once 'PHPMailerAutoload.php';
class Email{
public $fromEmailAddress;
public $displayName;
public $body;
public $toEmailaddress;
public function sendEmail(Email $email){
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'exploud-xxxxx.ny.xxxxxx.com'; // Specify main and backup server
$mail->setFrom($this->fromEmailAddress, $this->displayName);
//$mail->addAddress($email);
$mail->addAddress($this->toEmailaddress); // Add a recipient
$mail->addCC($this->fromEmailAddress);
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "Load Tender " . " - " . $this->displayName;
$mail->Body = $this->body;
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
return true;
}
}
Different php file, auto load the Email class: Take the Bill of Lading object that was created and email it
$bol = new Email();
$bol->body="Bill of Lading body";
$bol->displayName='Jon jonhnson';
$bol->fromEmailAddress = '[email protected]';
$bol->toEmailaddress = '[email protected]';
$bol->sendEmail($bol);
/**
*
*
*/
Take the tender object and email it $tender = new Email();
$tender->body="Tender body";
$tender->displayName='Jon jonhnson';
$tender->fromEmailAddress = '[email protected]';
$tender->toEmailaddress = '[email protected]';
$tender->sendEmail($tender);