I'm working on a class, what will be able to send e-mails for our customers. I need to help with review of my classes design. I'm trying to do it to be easy extendable in future. I'm thinking about using dependency injection to inject InputReaderInterface
. But is it worth doing it?
InputReaderInterface
- has method:getContent()
WebReader
- for reading source e-mail HTML (implementsInputReaderInterface
)ParamSetter
- for setting differentparams
for users (implementsInputReaderInterface
)$smtp
- class for saving access attributes for SMTPMailer
- uses PHPMailer class for sending e-mails
In the future, params
will be loaded from the database.
<?php
$reader1 = new WebReader($mailUrl);
$message = $reader1->getContent();
$params = array(
"[email protected]" => array(
"customer" => "Name Surname"
)
);
$reader2 = new ParamSetter($message, $params);
$mailer = new Mailer($smtp, $from, $alias);
foreach($rows as $row) {
$reader2->setParamsFor($row["email"]);
$message = $reader2->getContent();
$mailer->sendMail($row["email"], $subject, $message);
}
?>