<?php

require 'class.phpmailer.php';
require 'class.smtp.php';
require 'class.pop3.php';

$mail->SMTPDebug  = 1;

$config = parse_ini_file("/home/triarc3/mailer_config.ini");
$mail = new PHPMailer;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'mail.triarcladders.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = $config["username"];                            // SMTP username
$mail->Password = $config["password"];                           // SMTP password

$mail->From = 'configurator@triarcladders.com';
$mail->FromName = 'Tri-Arc Configurator';
$mail->addAddress('ron@tri-arc.com');  // Add a recipient
$mail->WordWrap = 80;                                 // Set word wrap to 50 characters
$mail->isHTML(true);                                  // Set email format to HTML
$data = substr($_POST["image"], strpos($_POST["image"], ","));
$encoding = 'base64';
$type='image/png';
$mail->addStringAttachment(base64_decode($data), 'Configuration.png', $encoding,$type); 
$data = substr($_POST["overviewImage"], strpos($_POST["overviewImage"], ","));
$mail->addStringAttachment(base64_decode($data), 'TopDownConfiguration.png', $encoding,$type); 

$mail->Subject = 'Ladder Quote Request From '.$_POST["name"];
$mail->Body    = 'Customer Name: '.$_POST["name"].'<BR>Company Name: '.$_POST["company"].'<BR>Phone Number: '.$_POST["phone"].'<BR>Email: '.$_POST["email"].'<BR>Referrer:'.$_POST["referrer"].'<BR>Comments:'.$_POST["comments"].'<BR><BR>Parts:<BR>'.$_POST["parts"].'<BR><BR>';

if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';
