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 |
| 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 | ?> |