<?php
if($actionmode == "sendemail"){
    $to = $txtemail;
    $mail = new PHPMailer(true);
    $mail->IsSMTP();
    $mail->Host = $config['host_rma'];
    $mail->SMTPAuth = true;
    $mail->Username = $config['username_rma'];
    $mail->Password = $config['password_rma'];
    $mail->CharSet = 'windows-1256';
    $mail->From = $config['fromemail_rma'];
    $mail->FromName = $config['fromname_rma'];
    $mail->WordWrap = 50;
    $mail->IsHTML(true);
    if ($cc != '')
        $mail->addCC($cc);
    $subject = "Statement of Items";
    $mail->Subject = $subject;
    $mail->AddAddress($to," ");
    $mail->AddEmbeddedImage('SignatureRMADepartment.jpg', 'SignatureRMADepartment');
    var str = "rep_statementofaccount.php?fromdate=01/01/2018&todate=$date&fromledger=$client_code&toledger=$client_code&fromproject=&fromcst=&fromcur=&dateoption=1&transaction=3&ledgeroption=1&curr=1&currbase1=0&currbase2=0&cum=0&alltypes=0&exclude=0&jvtype=&showunposted=0&prtfolio=1&prtref=1&prtdesc=1&prtvaluedate=1&prtjvtype=0&prtcostcent=0&prtproject=0&prevbal=1&dtjv=0&dtdate=1&checks=1&cltcst=&cltprj=&parentprj=0&prtaging=0&prtheader=1&prtcstjour=0&prtwording=0&salesman=&prtwnac=0&allow_zero_balance=0&from_balance=-0.5&to_balance=0.5&listaccounts=undefined";
    var xhttp = new XMLHttpRequest();
    //alert(str);exit;
    xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
        var data = xhttp.responseText.split('[BRK]');
        
    $mail->Body =  $html;
    //$mail->Body = iconv('windows-1256', 'utf-8', $html);
    //$mail->Body .= iconv('utf-8', 'windows-1256', $html);
    $mail->SMTPDebug = 0;
    $mail->Port =26;
    //$mail->Port =587;
    $mail->SMTPKeepAlive = true;  
    $mail->Mailer = "smtp"; 
    try {
        $mail->Send();
        $msg = 1;
        //echo $msg;

    } catch (phpmailerException $e) {
        $msg = 0;
        //echo $msg;
    }
    echo $msg;
    echo "[BRK]";
?>