Skip to content

Commit 1f36e1c

Browse files
committed
improved PHPMail for extending
1 parent 3237fb0 commit 1f36e1c

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/Notification/Implementation/PHPMail.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public function setFromAddress($from) {
2424

2525
public function addAddress($address, $type = null) {
2626
switch ($type){
27-
case self::CC :
27+
case self::CC :
2828
$this->cc[] = $address;
2929
break;
30-
case self::BCC :
30+
case self::BCC :
3131
$this->bcc[] = $address;
3232
break;
3333
default:
@@ -46,20 +46,37 @@ public function setMessage($message) {
4646
}
4747

4848
public function send() {
49-
$to = implode(", ", $this->to);
49+
return mail($this->getTo(),$this->getSubject(),$this->getMessage(),$this->getHeaders());
50+
}
51+
52+
protected function getTo(){
53+
return implode(", ", $this->to);
54+
}
55+
56+
protected function getSubject(){
57+
return $this->subject;
58+
}
59+
60+
protected function getMessage(){
61+
return $this->message;
62+
}
63+
64+
protected function getHeaders(){
5065
$cc = implode(", ", $this->cc);
5166
$bcc = implode(", ", $this->cc);
5267

53-
$headers = array_map(function($name,$value){return $name.": ".$value;},$this->headers);
68+
$headers = array();
69+
foreach ($this->headers as $name=>$value){
70+
$headers[] = "$name: $value";
71+
}
72+
5473
if(trim($cc) !== ""){
5574
$headers[] = "Cc: $cc";
5675
}
5776
if(trim($bcc) !== ""){
5877
$headers[] = "Bcc: $bcc";
5978
}
6079

61-
$header = implode("\r\n", $headers);
62-
63-
return mail($to,$this->subject,$this->message,$header);
80+
return implode("\r\n", $headers);
6481
}
6582
}

0 commit comments

Comments
 (0)