The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Send fpdf with phpmailer as an attachment
Discuss Send fpdf with phpmailer as an attachment in the PHP Development forum on Dev Shed. Send fpdf with phpmailer as an attachment PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 1st, 2013, 06:28 AM
|
|
Contributing User
|
|
Join Date: Sep 2004
Location: Marbella, Spain
Posts: 383
Time spent in forums: 6 Days 8 h 41 m 34 sec
Reputation Power: 0
|
|
|
Send fpdf with phpmailer as an attachment
Hi,
first I did a simply fpdf script on the fly with values from the database and I sent it using phpmailer without any problems.
Then I worked the fpdf script and added header, footer and phpscripts and queries to get an elaborated fpdf file.
The file is printed perfectly in the browser, but I cant manage to send it anymore.....
This is the fpdf file:
PHP Code:
class PDF extends FPDF
{
function Header()
{
$this->Image('paypal/headeringles2.png',10,5,190);
$this->SetFont('Arial','B',17);
// Salto de línea
$this->Ln(6);
global $propiedad;
$this->Cell(190,10,$propiedad,0,0,'C');
$this->Ln(16);
}
function Footer()
{
$this->SetFont('Arial','',10);
// Número de página
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
define('EUR', iconv('UTF-8', 'windows-1252', "€"));
define('DEG', iconv('UTF-8', 'windows-1252', "º"));
define('SEP', iconv('UTF-8', 'windows-1252', "'"));
// Creación del objeto de la clase heredada
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','',11);
$pdf->SetX(20);
$pdf->Cell(170,5,'Name: ' . $row->name,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Passport: ' . $row->passport,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Email: ' . $row->emailtrue,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Home phonenumber: ' . $row->telhome,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Movile to bring on holiday: ' . $row->telmobile,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Adults: ' . $row->adults,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Children (2-17 years): ' . $row->children,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Infants (under 2 years): ' . $row->babies,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$row->propiedad = str_replace(" ", "_", $row->propiedad);
$casa = $row->propiedad;
$result = mysql_query ("SELECT Duermen_max, bond FROM Casas_alquilar where (nombre = '$casa')");
while ($rows = mysql_fetch_object($result)) {
$pdf->Cell(170,5,utf8_decode("Máx. occupacy is ") . $rows->Duermen_max . ' persons excluding babies or infants who sleep in a cot for which there is',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'no extra charge.',0,0);
$pdf->Ln(12);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Property rented: ' .$row->propiedad,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Arrival: ' . $row->llegada,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Departure: ' .$row->salida,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
if ($row->percentage=="25"){$whenpayment = $whenpayment = "is due 8 weeks before arrival";}
if ($row->percentage=="50"){$whenpayment = "is due on arrival";}
$pdf->Cell(170,5, 'Total Holiday Cost: '. $row->holidaycost.EUR,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Option choosen to pay:',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'deposit ('.$row->percentage .' %) ' .$row->deposit.EUR.' balance ' .$row->balance.EUR. ' '. $whenpayment.'.',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'balance ' .$row->balance.EUR. ' '. $whenpayment.'.',0,0);
$pdf->Ln(6);
if ($row->bond=="tarjeta"){
$pdf->SetX(20);
$pdf->Cell(170,5, 'A damage deposit will be paid on arrival by creditcard.',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'I have read the booking conditions and agree to abide by them.',0,0);
$pdf->Ln(12);
}
else {
$pdf->SetX(20);
$pdf->Cell(170,5, 'A damage deposit of ' . $row->damagedeposit.EUR. ' wich will be returned after inspection will be blocked on my credit',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'card or paid on arrival in cash in the currency of my choice.',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'I have read the booking conditions and agree to abide by them.',0,0);
$pdf->Ln(12);
}
$pdf->SetX(20);
$pdf->Cell(170,5, 'Flight or other transport information, arriving: ' . $row->transport,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Arrival and departure time at airport, trainstation or property: ',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Arrival time: ' .$row->hourarrival,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Departure time: ' .$row->hourdeparture,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Arrival flight: ' .$row->arrivalflightdetails,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Departure flight: ' .$row->departureflightdetails,0,0);
$pdf->Ln(12);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Services required: (Air Port pickup to be paid on arrival) ',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Taxi' .SEP.'s up to 4 persons: ' .$row->taxismall,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Taxi'.SEP.'s up to 7 persons: ' .$row->taxibig,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'n'.DEG.' and group of Rent a car'.SEP.'s: ' .$row->rentacar,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'n'.DEG.' of cots (free of charge): ' .$row->cot,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Other services: ' .$row->otherservices,0,0);
$pdf->Ln(9);
$pdf->SetFont('Arial','',8);
$pdf->SetX(20);
$pdf->Cell(170,5, 'All charges of bank transfers to be paid by the guest. If the option of credit or debit card payment is chosen there will be a 4% charge to the guest.',0,0);
$pdf->Ln(4);
$pdf->Image('paypal/footeringles2.png',40,278,140);
}
$pdf->Output();
And this is the way I did sent it before using phpmailer:
$doc=$pdf->Output('Booking /' .$row->hourdeparture.'/','S');
$mail->AddStringAttachment($doc, 'Booking /' .$row->hourdeparture.'/', 'base64', 'application/pdf');
$mail->Send();
Any help please
|

January 1st, 2013, 12:20 PM
|
|
Contributing User
|
|
Join Date: Sep 2004
Location: Marbella, Spain
Posts: 383
Time spent in forums: 6 Days 8 h 41 m 34 sec
Reputation Power: 0
|
|
|
Changing $pdf new PDF (); to
$pdf=new FPDF('P','mm','A4');
trying to debug I managed to send (not sure all but at least what I tried)
However the image in the header did not appear on the pdf I received.
Maybe the file should be saved and then sent?
Any ideas as I ever sent attachments or saved files?
|

January 2nd, 2013, 06:27 AM
|
|
Contributing User
|
|
Join Date: Sep 2004
Location: Marbella, Spain
Posts: 383
Time spent in forums: 6 Days 8 h 41 m 34 sec
Reputation Power: 0
|
|
This now works if anybody is interested:
PHP Code:
class PDF extends FPDF
{
function Header()
{
$this->Image('headeringles2.png',10,5,190);
$this->SetFont('Arial','B',17);
// Salto de línea
$this->Ln(6);
global $propiedad;
$this->Cell(190,10,$propiedad,0,0,'C');
$this->Ln(16);
}
function Footer()
{
$this->SetFont('Arial','',10);
// Número de página
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
define('EUR', iconv('UTF-8', 'windows-1252', "€"));
define('DEG', iconv('UTF-8', 'windows-1252', "º"));
define('SEP', iconv('UTF-8', 'windows-1252', "'"));
// Creación del objeto de la clase heredada
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','',11);
$pdf->SetX(20);
$pdf->Cell(170,5,'Name: ' . $row->name,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Passport: ' . $row->passport,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Email: ' . $row->emailtrue,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Home phonenumber: ' . $row->telhome,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Movile to bring on holiday: ' . $row->telmobile,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Adults: ' . $row->adults,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Children (2-17 years): ' . $row->children,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Infants (under 2 years): ' . $row->babies,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$row->propiedad = str_replace(" ", "_", $row->propiedad);
$casa = $row->propiedad;
$result = mysql_query ("SELECT Duermen_max, bond FROM Casas_alquilar where (nombre = '$casa')");
while ($rows = mysql_fetch_object($result)) {
$pdf->Cell(170,5,utf8_decode("Máx. occupacy is ") . $rows->Duermen_max . ' persons excluding babies or infants who sleep in a cot for which there is',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'no extra charge.',0,0);
$pdf->Ln(12);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Property rented: ' .$row->propiedad,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Arrival: ' . $row->llegada,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Departure: ' .$row->salida,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
if ($row->percentage=="25"){$whenpayment = $whenpayment = "is due 8 weeks before arrival";}
if ($row->percentage=="50"){$whenpayment = "is due on arrival";}
$pdf->Cell(170,5, 'Total Holiday Cost: '. $row->holidaycost.EUR,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Option choosen to pay:',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'deposit ('.$row->percentage .' %) ' .$row->deposit.EUR,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'balance ' .$row->balance.EUR. ' '. $whenpayment.'.',0,0);
$pdf->Ln(6);
if ($row->bond=="tarjeta"){
$pdf->SetX(20);
$pdf->Cell(170,5, 'A damage deposit will be paid on arrival by creditcard.',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'I have read the booking conditions and agree to abide by them.',0,0);
$pdf->Ln(12);
}
else {
$pdf->SetX(20);
$pdf->Cell(170,5, 'A damage deposit of ' . $row->damagedeposit.EUR. ' wich will be returned after inspection will be blocked on my credit',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'card or paid on arrival in cash in the currency of my choice.',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'I have read the booking conditions and agree to abide by them.',0,0);
$pdf->Ln(12);
}
$pdf->SetX(20);
$pdf->Cell(170,5, 'Flight or other transport information, arriving: ' . $row->transport,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Arrival and departure time at airport, trainstation or property: ',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Arrival time: ' .$row->hourarrival,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Departure time: ' .$row->hourdeparture,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Arrival flight: ' .$row->arrivalflightdetails,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Departure flight: ' .$row->departureflightdetails,0,0);
$pdf->Ln(12);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Services required: (Air Port pickup to be paid on arrival) ',0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Taxi' .SEP.'s up to 4 persons: ' .$row->taxismall,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5,'Taxi'.SEP.'s up to 7 persons: ' .$row->taxibig,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'n'.DEG.' and group of Rent a car'.SEP.'s: ' .$row->rentacar,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'n'.DEG.' of cots (free of charge): ' .$row->cot,0,0);
$pdf->Ln(6);
$pdf->SetX(20);
$pdf->Cell(170,5, 'Other services: ' .$row->otherservices,0,0);
$pdf->Ln(9);
$pdf->SetFont('Arial','',8);
$pdf->SetX(20);
$pdf->Cell(170,5, 'All charges of bank transfers to be paid by the guest. If the option of credit or debit card payment is chosen there will be a 4% charge to the guest.',0,0);
$pdf->Ln(4);
$pdf->Image('footeringles2.png',40,278,140);
}
$pdf->Output("bookings/filename55.pdf","F");
$path = "bookings/filename55.pdf";
using this to send with phpmailer:
PHP Code:
$asunto = "$row->propiedad, $row->llegada - $row->salida";
$mail->AddAttachment($path, $asunto, $encoding = 'base64', $type = 'application/pdf');
if(!$mail->Send())
{
echo "Message could not be sent, enter a valid e-mail. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|