<?php

	function send_email($email, $name, $subject, $message){

		global $db;

		$siteSettings = $db->from('settings')->where('id', 1)->first();
		$mailSettings = $db->from('smtp_settings')->where('id', 1)->first();
	    $mail = new PHPMailer(true);

	    if($mailSettings['smtp_ssl'] == 1){
	    	$secure = "ssl";
	    }else{
	    	$secure = "tls";
	    }
	    try {

	        //$mail->SMTPDebug = 2;
	        $mail->isSMTP();
	        $mail->Host = $mailSettings['smtp_host'];
	        $mail->SMTPAuth = true;
	        $mail->Username = $mailSettings['smtp_email'];
	        $mail->Password = $mailSettings['smtp_password'];
	        $mail->SMTPSecure = $secure;
	        $mail->Port = $mailSettings['smtp_port'];
	        $mail->CharSet = 'UTF-8';

	        $mail->setFrom($mailSettings['smtp_email'], $siteSettings['site_title']);
	        $mail->addAddress($email, $name);

	        $mail->isHTML(true);
	        $mail->Subject = $subject;
	        $mail->Body = $message;

	        $mail->send();
	        $message = "Parola sıfırlama bağlantınız, mail adresinize gönderilmiştir.";
	        return $message;

	    } catch (Exception $e) {
	        $message = 'Message could not be sent. Mailer Error: '. $mail->ErrorInfo;
	        return $message;
	    }

	}