Skip to content

Commit 3297764

Browse files
committed
ad
1 parent db3f30c commit 3297764

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

a.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

b.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b

readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ $to = '[email protected]'; // 发送人
4747
$subject = '测试标题'; // 邮件标题
4848
$body = "<p>测试内容</p>"; // 邮件内容支持html
4949

50+
// 添加附件
51+
// $attachments = [
52+
// ['a.txt' , 'a'],
53+
// ['b.txt' , 'b']
54+
// ];
55+
// $mail->addAttachments($attachments);
56+
5057
$res = $mail->sent($to, $subject, $body);
5158

5259

src/Mail.php

+20-10
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,7 @@ public function sent($to , $subject , $body , $replyTo = NULL , $attachments = n
5454
if ($replyTo){
5555
$this->mail->addReplyTo($replyTo);
5656
}
57-
if ($attachments){
58-
foreach ($attachments as $a){
59-
if (is_array($a)){
60-
$this->mail->addAttachment($a[0] , $a[1]);
61-
}else{
62-
$this->mail->addAttachment($a);
63-
}
64-
65-
}
66-
}
57+
6758

6859
$this->mail->isHTML(true);
6960
$this->mail->Subject = $subject;
@@ -78,6 +69,25 @@ public function sent($to , $subject , $body , $replyTo = NULL , $attachments = n
7869
}
7970
}
8071

72+
/**
73+
* 添加附件
74+
*/
75+
public function addAttachments($attachments){
76+
77+
if ($attachments){
78+
foreach ($attachments as $a){
79+
if (is_array($a)){
80+
$this->mail->addAttachment($a[0] , $a[1]);
81+
}else{
82+
$this->mail->addAttachment($a);
83+
}
84+
85+
}
86+
}
87+
88+
return true;
89+
}
90+
8191
public function addReplyTo($address , $name = ''){
8292

8393
$this->mail->addReplyTo($address , $name);

test.php

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
3737
$subject = '测试标题';
3838
$body = "<p>测试内容</p>";
39+
40+
// 添加附件
41+
// $attachments = [
42+
// ['a.txt' , 'a'],
43+
// ['b.txt' , 'b']
44+
// ];
45+
// $mail->addAttachments($attachments);
46+
3947
$res = $mail->sent($to, $subject, $body);
4048

4149

0 commit comments

Comments
 (0)