matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 1 | <?php |
| 2 | require_once "Mail.php"; |
| 3 | include('Mail/mime.php'); |
| 4 | include 'config.php'; |
| 5 | |
| 6 | function send_mail(string $email, object $smtp, object $message) { |
Marc Kupietz | efd7cc2 | 2023-03-04 19:55:56 +0100 | [diff] [blame] | 7 | include 'config.php'; |
| 8 | |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 9 | $crlf = "\r\n"; |
| 10 | |
| 11 | $headers = array( |
| 12 | 'From' => $smtp->from, |
| 13 | 'To' => $email, |
| 14 | 'Subject' => $message->subject |
| 15 | ); |
| 16 | |
Marc Kupietz | efd7cc2 | 2023-03-04 19:55:56 +0100 | [diff] [blame] | 17 | 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 | |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 26 | $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 Kupietz | 0aba836 | 2023-03-09 20:39:47 +0100 | [diff] [blame] | 35 | $mime = new Mail_mime(array( |
| 36 | "text_charset" => "utf-8", |
| 37 | "html_charset" => "utf-8", |
| 38 | "eol" => $crlf |
| 39 | )); |
matheusfillipe | abd513e | 2021-05-11 03:29:11 -0300 | [diff] [blame] | 40 | |
| 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 | ?> |