i'm using an API to return a PDF. The php file that returns the PDF is "getndadata.php" and this is the response :
I'm then passing that response via ajax to another php file called sendpdf.This is the response.. (i know its getting the pdf data because its in the response text)
this is my code in "sendpdf.php"
<?php
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Access-Control-Allow-Methods: GET, POST, PUT');
header("Access-Control-Allow-Origin: *");
if(!empty($_POST['data'])){
$data = $_POST['data'];
include("phpmailer/class.phpmailer.php");
$account="XXX";
$password="XXX";
$to='XXX';
$from="XXX";
$from_name="XXX";
$msg='test';
$subject="NDA Recieved";
/*End Config*/
if(!empty($_POST['data'])){
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->addStringAttachment($data, 'NDA.pdf');
$mail->Host = "smtp.office365.com";
$mail->SMTPAuth= true;
$mail->Port = 587;
$mail->Username= $account;
$mail->Password= $password;
$mail->SMTPSecure = 'tls';
$mail->From = $from;
$mail->FromName= $from_name;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->addAddress($to);
if(!$mail->send()){
header('Content-Type: application/json');
echo json_encode(array('data:' => $mail->ErrorInfo));
}else{
echo json_encode(array('data' => $data));
}
}
} else {
echo json_encode(array('data' => 'no data sent'));
}
exit();
?>
Is there something i need to do with
$_POST['data'];
?
This is my ajax call :
var serverurl = 'XXXX/getnda.php?url=' + "<?php echo $url ?>&" + "<?php echo $ip ?>" ;
console.log("severurl : " + serverurl);
var response = $.ajax({
type: "GET",
url: serverurl,
cache: false,
complete: function(data){
var fdata = JSON.stringify(data);
once = true;
var serverurl2 = 'http://XXXXX/sendpdf.php';
$.ajax({
method: "POST",
url: serverurl2,
data: {data: fdata},
}).done(function(data){
console.log(data);
console.log("email should be sent");
});
}
});