Skip to content

Commit 56899d2

Browse files
committed
Reformat code in mailers, update readme with replyTo
1 parent ca433df commit 56899d2

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Desktop.ini
1515

1616
# composer itself is not needed
1717
composer.phar
18+
composer.lock
1819

1920
# phpunit itself is not needed
2021
phpunit.phar

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Example:
170170
$messageConfig = [
171171
'from' => ['[email protected]' => 'My Domain Support'],
172172
'to' => ['[email protected]' => 'John Doe'],
173+
'replyTo' => ['[email protected]' => 'REPLY NAME'], // OPTIONAL
173174
'cc' => ['[email protected]', '[email protected]'], // OPTIONAL
174175
'bcc' => ['[email protected]'], // OPTIONAL
175176
'subject' => 'Contact request from {name}',
@@ -231,6 +232,7 @@ $mailerConfig = [
231232
$messageConfig = [
232233
'from' => ['[email protected]' => 'FROM NAME'], // set correct FROM.
233234
'to' => ['[email protected]' => 'TO NAME'], // set correct TO.
235+
'replyTo' => ['[email protected]' => 'REPLY NAME'],// set correct REPLY.
234236
'subject' => 'Contact request from {name}',
235237
'bodyTemplate' => __DIR__ . '/template-html.php',
236238
'altBodyTemplate' => __DIR__ . '/template-plain.php',
@@ -384,6 +386,7 @@ After that you need to specify which files should be uploaded in `$messageConfig
384386
$messageConfig = [
385387
'from' => ['[email protected]' => 'FROM NAME'], // set correct FROM.
386388
'to' => ['[email protected]' => 'TO NAME'], // set correct TO.
389+
'replyTo' => ['[email protected]' => 'REPLY NAME'],// set correct REPLY.
387390
'subject' => 'Contact request from {name}',
388391
'bodyTemplate' => __DIR__ . '/template-html.php',
389392
'altBodyTemplate' => __DIR__ . '/template-plain.php',

composer.lock

+3-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Mailer/MandrillMailer.php

+18-16
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,23 @@ public function send(MailMessage $message)
5656
$mandrill = new Mandrill($this->apiKey);
5757

5858
$mandrillMessage = array(
59-
'html' => $message->getBody(),
60-
'subject' => $message->getSubject(),
59+
'html' => $message->getBody(),
60+
'subject' => $message->getSubject(),
6161
'from_email' => $message->getFrom()->getEmail(),
62-
'from_name' => $message->getFrom()->getName(),
62+
'from_name' => $message->getFrom()->getName(),
6363
);
64-
65-
$replyTo=$message->getReplyTo();
66-
if(!empty($replyTo)) {
67-
$mandrillMessage['headers']=['Reply-To' => $replyTo->getEmail()];
64+
65+
if ($replyTo = $message->getReplyTo()) {
66+
$mandrillMessage['headers'] = [
67+
'Reply-To' => $replyTo->getEmail(),
68+
];
6869
}
6970

7071
// Recipients.
7172
$recipients = [
72-
'to' => $message->getTo(),
73-
'cc' => $message->getCc(),
74-
'bcc' => $message->getBcc()
73+
'to' => $message->getTo(),
74+
'cc' => $message->getCc(),
75+
'bcc' => $message->getBcc(),
7576
];
7677

7778
$to = [];
@@ -82,8 +83,8 @@ public function send(MailMessage $message)
8283
foreach ($emails as $email) {
8384
$to[] = [
8485
'email' => $email->getEmail(),
85-
'name' => $email->getName(),
86-
'type' => $type
86+
'name' => $email->getName(),
87+
'type' => $type,
8788
];
8889
}
8990
}
@@ -92,14 +93,14 @@ public function send(MailMessage $message)
9293

9394
// Attachments.
9495
if (0 < $message->getAttachmentsSize() && $message->getAttachmentsSize() < $this->attachmentsSizeLimit
95-
&& $attachments = $message->getAttachments()
96+
&& $attachments = $message->getAttachments()
9697
) {
9798
$attachmentsArray = [];
9899
foreach ($attachments as $attachment) {
99100
$attachmentsArray[] = [
100-
'type' => $attachment->type,
101-
'name' => $attachment->name,
102-
'content' => $attachment->getBase64()
101+
'type' => $attachment->type,
102+
'name' => $attachment->name,
103+
'content' => $attachment->getBase64(),
103104
];
104105
}
105106

@@ -111,6 +112,7 @@ public function send(MailMessage $message)
111112
return $result;
112113
} catch (Mandrill_Error $e) {
113114
$this->errors[] = 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
115+
114116
return false;
115117
}
116118
}

src/Mailer/PHPMailer.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ public function send(MailMessage $message)
7575
$mail = new PHPMailerLib(true); // Passing `true` enables exceptions.
7676
try {
7777
// Enable SMTP if host is set.
78-
if (!empty($this->host)) {
78+
if (! empty($this->host)) {
7979
$mail->SMTPDebug = 0;
8080
$mail->isSMTP();
8181
$mail->Host = $this->host;
8282
$mail->Port = $this->port;
83-
if (!empty($this->user)) {
83+
if (! empty($this->user)) {
8484
$mail->SMTPAuth = true;
8585
$mail->Username = $this->user;
8686
$mail->Password = $this->password;
8787
}
88-
if (!empty($this->protocol)) {
88+
if (! empty($this->protocol)) {
8989
$mail->SMTPSecure = $this->protocol;
9090
}
9191
}
@@ -138,13 +138,15 @@ public function send(MailMessage $message)
138138
$mail->Body = $message->getBody();
139139
$mail->AltBody = $message->getAltBody();
140140
} else {
141-
$mail->Body = $message->getAltBody();
141+
$mail->Body = $message->getAltBody();
142142
}
143143

144144
$this->errors = array();
145+
145146
return $mail->send();
146147
} catch (PhpMailerException $e) {
147148
$this->errors[] = 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
149+
148150
return false;
149151
}
150152
}

0 commit comments

Comments
 (0)