<?
error_reporting( E_ALL ^ E_NOTICE ^ E_STRICT ^ E_WARNING ^ E_DEPRECATED );
header('Access-Control-Allow-Origin: *');
require_once '../settings.php';
require_once 'phpmailer/class.phpmailer.php';
require_once 'phpmailer/class.smtp.php';

$json = json_decode( $request_body = file_get_contents('php://input'), true );
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = $settings['email_host'];
$mail->Port = $settings['email_port'];
$mail->Username = $settings['email_login'];
$mail->Password = $settings['email_password'];
$mail->CharSet = "UTF-8";
$mail->SMTPOptions = array(
  'ssl' => array(
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
  )
);

$mail->AddReplyTo( $json['mail'], $json['mail'] );
$mail->SetFrom( 'www@cdn.projectpro.pl', 'www@cdn.projectpro.pl' );

$mail -> AddAddress( 'wojciech.kalejta@moodo.pl', '');
$mail -> AddAddress( 'dariusz.niewiadomski@moodo.pl', '');
$mail -> AddAddress( 'dniewiadomski@wp.pl', '');
$mail -> AddAddress( 'aleksander.dubowski@moodo.pl', '');
$mail -> AddAddress( 'robert.wojcicki@moodo.pl', '');
$mail -> AddAddress( 'biuro@project-pro.pl', '');

$mail->Subject = 'Współpraca franczyzowa - wiadomość';
$mail -> Body = '<p><b>Imię i nazwisko:</b> ' . $json['name'] . ' ' . $json['secondname'] . '</p>'
              . '<p><b>Email:</b> ' . $json['mail'] . '</p>'
              . '<p><b>Telefon:</b> ' . $json['tel'] . '</p>'
              . '<p><b>Miasto sklepu:</b> ' . $json['city'] . '</p>';
              // . '<p><b>Chcę odwiedzić moodo na targach 19-21 października:</b> ' . $json['fair'] . '</p>'
              // . '<p>' . $json['interesting_moodo'] . '</p>';
$mail->IsHTML(true);
// $mail -> SMTPDebug = 2;
$mail->Send();