Welcome Guest, Not a member yet? Register   Sign In
Email PDF Attachment Not Working
#1

[eluser]Kyle Wiebers[/eluser]
I'm trying to attach a pdf file, that gets returned by a helper function, to an email. Here is my code:
Code:
$this->load->helper(array('form', 'url','process'));
$this->load->library(array('form_validation','email','fpdf'));
$config['mailtype'] ='html';
$this->email->clear();
$this->email->initialize($config);
$this->email->from($_POST['email'],$_POST['firstname'].' '.$_POST['lastname']);
$this->email->to('myemail');
$this->email->subject('Application Test');
$this->email->message('Testing the pdf helper');
$pdf = createPDF();
$this->email->attach($pdf);
$this->email->send();
echo $this->email->print_debugger();
$this->load->view('jobs/application-success',$data);

and the helper function....
Code:
function createPDF() {
    $CI =& get_instance();
    $CI->fpdf->initialize('P','mm','A4');
    $CI->fpdf->AddPage();
    $CI->fpdf->SetFont('Arial','B',12);
    $CI->fpdf->Cell(40,10,'Name: '.$_POST['firstname'].' '.$_POST['lastname']);
    return $CI->fpdf->Output("","S");

Code:
Unable to locate the following email attachment: %PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream xœ3Rðâ2Ð35W(çr QÐw3T04Ò30PISp  êZ*˜[šê™›+„¤(hø%æ¦Z)$¦'¦)$§¤qš¦BHH=�­ÒS endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 5 0 R >> /XObject << >> >> endobj 6 0 obj << /Producer (FPDF 1.53) /CreationDate (D:20090210184646) >> endobj 7 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /FitH null] /PageLayout /OneColumn >> endobj xref 0 8 0000000000 65535 f 0000000236 00000 n 0000000424 00000 n 0000000009 00000 n 0000000087 00000 n 0000000323 00000 n 0000000528 00000 n 0000000604 00000 n trailer << /Size 8 /Root 7 0 R /Info 6 0 R >> startxref 707 %%EOF
Your message has been successfully sent using the following protocol: mail

User-Agent: CodeIgniter
Date: Tue, 10 Feb 2009 18:28:57 -0600
From: "agsaf asdgasdf"
Return-Path:
Reply-To: "asdgasdf"
X-Sender: asdgasdf
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <49921bc9e2742>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="B_ATC_49921bc9e32f4"
This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ATC_49921bc9e32f4
Content-Type: multipart/alternative; boundary="B_ALT_49921bc9e2f0e"

--B_ALT_49921bc9e2f0e
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Testing the pdf helper


--B_ALT_49921bc9e2f0e
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Application Test

With the attachment line included, there is not a body in the email at all, and without it the body says "Testing the pdf helper". The to fields in the header is just junk input that I put in since the form is un-sanitized.

Is there anyway to attach the pdf file returned from the createPDF() function?
#2

[eluser]hostcord[/eluser]
I think you should try saving the pdf as a temporary file, attaching it, then deleting it. Returning the value of the output method is not a file, simply the content of that file and not a file itself. That's my suggestion, hope it helps!




Theme © iAndrew 2016 - Forum software by © MyBB