phpmailer.php.example 1.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?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() {
	}

	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";
		$mail->isSMTP();
		$mail->SMTPDebug = 0; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
		$mail->Host = gethostbyname('replace your.mailrelay.org');
		//$mail->Port = 465; // TLS only
		$mail->Port = 587; // TLS only
		$mail->SMTPAuth = true;
		$mail->Username = 'replace username';
		$mail->Password = 'replace password';
		$mail->setFrom('example.org', 'Test IDP portal');
		if (security::check_request_data($to_name)) {
			$mail->addAddress($to, $to_name);
		} else {
			$mail->addAddress($to);
		}
		$mail->Subject = $subject;
		$mail->msgHTML($message); embedded,
		$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;
		}
	}
}
?>