blob: c0f3251711467c1ac01910bcd39088921f8c2dd5 [file] [log] [blame]
matheusfillipeabd513e2021-05-11 03:29:11 -03001<?php
2require_once "Mail.php";
3include('Mail/mime.php');
4include 'config.php';
5
6function send_mail(string $email, object $smtp, object $message) {
Marc Kupietzefd7cc22023-03-04 19:55:56 +01007 include 'config.php';
8
matheusfillipeabd513e2021-05-11 03:29:11 -03009 $crlf = "\r\n";
10
11 $headers = array(
12 'From' => $smtp->from,
13 'To' => $email,
14 'Subject' => $message->subject
15 );
16
Marc Kupietzefd7cc22023-03-04 19:55:56 +010017 if (isset($CC_MAIL)) {
18 $headers['Cc'] = $CC_MAIL;
19 $email .= ', ' . $CC_MAIL;
20 }
21
22 if (isset($BCC_MAIL)) {
23 $email .= ', ' . $BCC_MAIL;
24 }
25
matheusfillipeabd513e2021-05-11 03:29:11 -030026 $smtp = Mail::factory('smtp', array(
27 'host' => $smtp->host,
28 'port' => $smtp->port,
29 'auth' => true,
30 'username' => $smtp->username, //your gmail account
31 'password' => $smtp->password // your password
32 ));
33
34 // Creating the Mime message
Marc Kupietz0aba8362023-03-09 20:39:47 +010035 $mime = new Mail_mime(array(
36 "text_charset" => "utf-8",
37 "html_charset" => "utf-8",
38 "eol" => $crlf
39 ));
matheusfillipeabd513e2021-05-11 03:29:11 -030040
41 // Setting the body of the email
42 $mime->setTXTBody($message->text);
43 $mime->setHTMLBody($message->html);
44
45 $body = $mime->get();
46 $headers = $mime->headers($headers);
47
48 // Send the mail
49 $mail = $smtp->send($email, $headers, $body);
50
51 //check mail sent or not
52 if (PEAR::isError($mail)) {
53 return false;
54 } else {
55 return true;
56 }
57}
58
59/* send_mail("mattf@tilde.club", $SMTP, (object) [ */
60/* "subject" => "Please confirm your email", */
61/* "text" => "Plain tet", */
62/* "html" => "<html><body><p>HTML message</p><h2>This is not mere text</h2></body></html>" */
63/* ]) */
64?>