Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- require_once dirname(__DIR__) . '/vendor/autoload.php';
- use Simples\Mailer\PHPMailer;
- use Exception;
- /**
- * @param string $address
- * @param string $subject
- * @param string $message
- * @param string $attachment (null)
- * @return bool
- * @throws Exception
- */
- function mail($address, $subject, $message, $attachment = null)
- {
- $mail = new PHPMailer;
- $mail->Host = __SMTP_HOST__;
- $mail->Port = __SMTP_PORT__;
- $mail->SMTPSecure = __SMTP_SECURE__;
- $mail->SMTPAuth = true;
- $mail->Username = __SMTP_USERNAME__;
- $mail->Password = __SMTP_PASSWORD__;
- $mail->isSMTP();
- $mail->setFrom(__SMTP_FROM__);
- $mail->addAddress($address);
- $mail->CharSet="utf-8";
- $mail->Subject = $subject;
- $mail->Body = $message;
- $mail->MsgHTML($message);
- $mail->IsHTML(true);
- if ($attachment && isset($attachment['path']) && isset($attachment['name'])) {
- $mail->addAttachment($attachment['path'], $attachment['name']);
- }
- if (!$mail->send()) {
- throw new Exception($mail->ErrorInfo);
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement