phpmailer.php 1.41 KB
Newer Older
Martin van Es's avatar
Martin van Es committed
1
2
3
4
5
6
7
8
9
10
<?php
	use PHPMailer\PHPMailer\PHPMailer;
	use PHPMailer\PHPMailer\Exception;
	require_once(APP_BASE_DIR.'/classes/phpmailer/Exception.php');
	require_once(APP_BASE_DIR.'/classes/phpmailer/PHPMailer.php');
	require_once(APP_BASE_DIR.'/classes/phpmailer/SMTP.php');

class custom_phpmailer {
	public function __construct() {
	}
11

Martin van Es's avatar
Martin van Es committed
12
13
14
	public static function send_email($to, $to_name='', $subject='Message from Test IDP portal', $message, $success='Your account registration is pending') {
		$mail = new PHPMailer;
		$mail->CharSet = "UTF-8";
15
		$mail->isSMTP();
Martin van Es's avatar
Martin van Es committed
16
		$mail->SMTPDebug = 0; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
17
		$mail->Host = gethostbyname('replace your.mailrelay.org');
Martin van Es's avatar
Martin van Es committed
18
19
20
		//$mail->Port = 465; // TLS only
		$mail->Port = 587; // TLS only
		$mail->SMTPAuth = true;
21
22
23
		$mail->Username = 'replace username';
		$mail->Password = 'replace password';
		$mail->setFrom('example.org', 'Test IDP portal');
Martin van Es's avatar
Martin van Es committed
24
25
26
27
28
29
		if (security::check_request_data($to_name)) {
			$mail->addAddress($to, $to_name);
		} else {
			$mail->addAddress($to);
		}
		$mail->Subject = $subject;
30
		$mail->msgHTML($message); embedded,
Martin van Es's avatar
Martin van Es committed
31
32
33
34
35
		$mail->AltBody = strip_tags(str_replace('<br />', "\n\r", $message));
		if(!$mail->send()){
			return security::format_message("ERROR:Įvyko klaida siunčiant el. laišką. Prašome kreiptis į administratorių.");
		} else {
			return $success;
36
		}
Martin van Es's avatar
Martin van Es committed
37
38
39
	}
}
?>