0

I am creating a simple database where I can run a 1 click email with a PDF attached. Currently I'm running that with the TCPDF function but I want to be able to send data to the PDF script using AJAX.

If someone can reference to what I need to read up on I would be grateful as most examples I can find only include pulling data from text files

For example:

<a href="tcpdf/PDF/testPDF.php?firstname=Ralph&datetime=2014-07-10 09:15:00&[email protected]" target="_blank">Send Invitation</a>

If it helps here is my mail code:

// random hash necessary to send mixed content
$separator = md5(time());

$eol = PHP_EOL;

// attachment name
$filename = "Invitation.pdf";

// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));

///////////HEADERS INFORMATION////////////
// main header (multipart mandatory) message
$headers  = "From: test<[email protected]>".$eol;
$headers .= "Bcc: [email protected]".$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol; 
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;

// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;

// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";


//Email message
mail($emailto, $emailsubject, $emailbody, $headers);
3
  • What data do you want to send? Commented Jul 5, 2014 at 15:14
  • All I'm trying to do is essentially 'run' the hyperlink rather than navigate to the actual page Commented Jul 5, 2014 at 15:15
  • Here you are: api.jquery.com/jquery.get Commented Jul 5, 2014 at 15:19

1 Answer 1

2

Use $.get to perform a GET using AJAX.

$("a").click(function(e) {
    e.preventDefault(); // Don't follow the link
    $.get(this.href, function(response) {
        // Display response
    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! Wheres the best place to go to read up on how to expand on this?
@JosephGregory The jQuery documentation, I've added a link to it in the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.