<?php

// setup
$emails  = ['info@seoptimizer.ae', 'assyl@seoptimizer.ae']; // can be array or string
$subject = 'Request from seoptimizer.ae';
$data    = $_POST;

// process
if (count($data)) {
	
	if (!is_array($emails)) {
		$emails = [$emails];
	}

    // format message
    $message = '';
    foreach ($data as $key => $value) {
        $key = str_replace(['-', '_'], ' ', $key);
        $key = ucwords($key);
        $message .= "{$key}: {$value}<br>\r\n";
    }
    $message .= "IP: {$_SERVER['REMOTE_ADDR']}<br>\r\n";
    if ( ! empty($_SERVER['HTTP_REFERER'])) {
        $message .= "Referrer: {$_SERVER['HTTP_REFERER']}<br>\r\n";
    }
    $message .= "Datetime: " . date('Y-m-d H:i:s');
	
	require_once __DIR__ . '/class.phpmailer.php';
	require_once __DIR__ . '/class.smtp.php';
	
	$mail = new PHPMailer;

	#$mail->SMTPDebug = 3;                              // Enable verbose debug output

	$mail->isSMTP();                                    // Set mailer to use SMTP
	$mail->Host = 'smtp.yandex.com';  				// Specify main and backup SMTP servers
	$mail->SMTPAuth = true;                             // Enable SMTP authentication
	$mail->Username = 'no-reply@betterweb.ae';           // SMTP username
	$mail->Password = 'vRyt9oubjg22ZBG2v3Tc2fRq';                     // SMTP password
	$mail->SMTPSecure = 'ssl';                        // Enable TLS encryption, `ssl` also accepted
	$mail->Port = 465;                                   // TCP port to connect to
#	$mail->SMTPOptions = [
#	    'ssl' => [
#		'verify_peer' => false,
#		'verify_peer_name' => false,
#		'allow_self_signed' => true,
#	    ]
#	];
	$mail->CharSet = 'UTF-8';

	//$mail->AddReplyTo($data['email']);
	$mail->setFrom('no-reply@betterweb.ae');
	
	foreach ($emails as $email) {
		$mail->addAddress($email);
	}
	$mail->addBCC('assylibraim@gmail.com');

	$mail->Subject = $subject;
	$mail->Body    = $message;
	$mail->AltBody = str_replace('<br>', '', $message);

	$mail->send();
}