[Solved] How can i generate an excel file and save it into the local directory and send it with a mail as an attachment using phpmailer [closed]


include 'connection.php';
include 'phpmailer/PHPMailerAutoload.php';    
$name=$_POST['details'];
$location=$_POST['from'];
$city=$_POST['to'];
$state=$_POST['message'];
$branch=$_POST['client'];
$email=$_POST['email'];
$date=date('Y-m-d');
$columnHeader="";
$columnHeader =  "Details" . "\t" ."From Date" . "\t". "To Date" . "\t". "Message" .  "\t". "Hotel" . "\t" . "Email" . "\t" . "Date" ;
$setData="";
$newarray = array('details'=>$name,'fromdate'=>$location,'todate'=>$city,'message'=>$state,'hotel'=>$branch,'email'=>$email,'date'=>$date);
$rowData="";
foreach ($newarray as $value) {

    $value=""" . $value . '"' . "\t";
    $rowData .= $value;

}
$setData .= trim($rowData) . "\n";
$filename="filename";
$file="Directory/".$filename.'.extension';

$mmm= ucwords($columnHeader)."\n".$setData;
$fo = fopen($file,"w");

fwrite($fo,$mmm);
$inser="insert into tablename(field1,field2,field3,field4,field5,field6,field7,field8,field9)values ('$name','$location','$city','$state',$hotel3,'$email','$date','Nothing','pending')";
$g=sqlsrv_query($conn,$inser);
if($g)
{


    $from_name="Client";
    $to = "sendingmailid.com"; // this is the sender's Email address

    $subject="Subject";        
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure="ssl"; // secure transfer enabled REQUIRED for Gmail
    $mail->Host="*********";
    $mail->Port = *;
    $mail->Username = "************";
    $mail->Password = "*************";
    $mail->SetFrom($email,$from_name,$email);
    $mail->Subject = $from_name;
    $mail->AddAttachment($file);
    $mail->Body = "Message From: ".$email."\n\n"."Subject: ".$subject;
    $mail->AddAddress($to);
    if(!$mail->Send()) {

        $error="Mail error: ".$mail->ErrorInfo;
        return false;
    } else {
        ?>
    <script>
        window.location='filename.php';

        alert("We will Contact you soon");
    </script>
    <?php
        $error="Message sent!";
        return true;
    }

}

solved How can i generate an excel file and save it into the local directory and send it with a mail as an attachment using phpmailer [closed]