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) { |
| 7 | $crlf = "\r\n"; |
| 8 | |
| 9 | $headers = array( |
| 10 | 'From' => $smtp->from, |
| 11 | 'To' => $email, |
| 12 | 'Subject' => $message->subject |
| 13 | ); |
| 14 | |
| 15 | $smtp = Mail::factory('smtp', array( |
| 16 | 'host' => $smtp->host, |
| 17 | 'port' => $smtp->port, |
| 18 | 'auth' => true, |
| 19 | 'username' => $smtp->username, //your gmail account |
| 20 | 'password' => $smtp->password // your password |
| 21 | )); |
| 22 | |
| 23 | // Creating the Mime message |
| 24 | $mime = new Mail_mime($crlf); |
| 25 | |
| 26 | // Setting the body of the email |
| 27 | $mime->setTXTBody($message->text); |
| 28 | $mime->setHTMLBody($message->html); |
| 29 | |
| 30 | $body = $mime->get(); |
| 31 | $headers = $mime->headers($headers); |
| 32 | |
| 33 | // Send the mail |
| 34 | $mail = $smtp->send($email, $headers, $body); |
| 35 | |
| 36 | //check mail sent or not |
| 37 | if (PEAR::isError($mail)) { |
| 38 | return false; |
| 39 | } else { |
| 40 | return true; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /* send_mail("mattf@tilde.club", $SMTP, (object) [ */ |
| 45 | /* "subject" => "Please confirm your email", */ |
| 46 | /* "text" => "Plain tet", */ |
| 47 | /* "html" => "<html><body><p>HTML message</p><h2>This is not mere text</h2></body></html>" */ |
| 48 | /* ]) */ |
| 49 | ?> |