blob: 1432a265173b758be209b7564d90bdd4d7a3c0b3 [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
35 $mime = new Mail_mime($crlf);
36
37 // Setting the body of the email
38 $mime->setTXTBody($message->text);
39 $mime->setHTMLBody($message->html);
40
41 $body = $mime->get();
42 $headers = $mime->headers($headers);
43
44 // Send the mail
45 $mail = $smtp->send($email, $headers, $body);
46
47 //check mail sent or not
48 if (PEAR::isError($mail)) {
49 return false;
50 } else {
51 return true;
52 }
53}
54
55/* send_mail("mattf@tilde.club", $SMTP, (object) [ */
56/* "subject" => "Please confirm your email", */
57/* "text" => "Plain tet", */
58/* "html" => "<html><body><p>HTML message</p><h2>This is not mere text</h2></body></html>" */
59/* ]) */
60?>