-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_mailsend.php
59 lines (43 loc) · 2.1 KB
/
template_mailsend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
class Mail {
private $from;
private $from_name = "";
private $type = "text/html";
private $encoding = "utf-8";
private $notify = false;
/* Конструктор принимающий обратный e-mail адрес */
public function __construct($from) {
$this->from = $from;
}
/* Изменение обратного e-mail адреса */
public function setFrom($from) {
$this->from = $from;
}
/* Изменение имени в обратном адресе */
public function setFromName($from_name) {
$this->from_name = $from_name;
}
/* Изменение типа содержимого письма */
public function setType($type) {
$this->type = $type;
}
/* Нужно ли запрашивать подтверждение письма */
public function setNotify($notify) {
$this->notify = $notify;
}
/* Изменение кодировки письма */
public function setEncoding($encoding) {
$this->encoding = $encoding;
}
/* Метод отправки письма */
public function send($to, $subject, $message) {
$from = "=?utf-8?B?".base64_encode($this->from_name)."?="." <".$this->from.">"; // Кодируем обратный адрес (во избежание проблем с кодировкой)
$headers = "From: ".$from."\r\nReply-To: ".$from."\r\nContent-type: ".$this->type."; charset=".$this->encoding."\r\n"; // Устанавливаем необходимые заголовки письма
if ($this->notify) {
$headers .= "Disposition-Notification-To: ".$this->from."\r\n"; // Добавляем запрос подтверждения получения письма, если требуется
}
$subject = "=?utf-8?B?".base64_encode($subject)."?="; // Кодируем тему (во избежание проблем с кодировкой)
return mail($to, $subject, $message, $headers); // Отправляем письмо и возвращаем результат
}
}
?>