xref: /web-master/include/mailer.php (revision 369ff201)
1<?php
2
3use PHPMailer\PHPMailer\PHPMailer;
4use PHPMailer\PHPMailer\Exception;
5
6require 'PHPMailer/src/Exception.php';
7require 'PHPMailer/src/PHPMailer.php';
8require 'PHPMailer/src/SMTP.php';
9
10class MailAddress {
11    public $email;
12    public $name;
13
14    public function __construct($email, $name = '') {
15        $this->email = $email;
16        $this->name = $name;
17    }
18
19    public static function noReply($name = '') {
20        return new self('noreply@php.net', $name);
21    }
22}
23
24function mailer($to, $subject, $body, MailAddress $from, array $replyTos = []) {
25    $mail = new PHPMailer;
26    $mail->isSMTP();
27    $mail->SMTPDebug = 0;
28    $mail->Host = 'mailout.php.net';
29    $mail->Port = 25;
30    $mail->CharSet = 'utf-8';
31    foreach ($replyTos as $replyTo) {
32        $mail->addReplyTo($replyTo->email, $replyTo->name);
33    }
34    $mail->setFrom($from->email, $from->name);
35    $mail->addAddress($to);
36    $mail->Subject = $subject;
37    $mail->Body = $body;
38    $mail_sent = $mail->send();
39}
40