Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8336261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:55:46+00:00 2026-06-09T03:55:46+00:00

I have a PHP script which emails someone 2 images when they have completed

  • 0

I have a PHP script which emails someone 2 images when they have completed a payment via paypal. Now 1 of these images has text added to it via the imagettftext function.

Now what I am looking to do, is instead of email the 2 images, I want the 2 images to be added to a PDF file on their own pages, and then have that PDF file emailed to them.

Heres my code for the email which sends the images:

$sql = mysql_query("select * from `bookings` where `id`='$order_id'");

while ($row = mysql_fetch_assoc($sql))
{
    foreach ($row as $k => $v)
        $$k = $v;

    $img = imagecreatefrompng("ticket-blank.png");

    if (!empty($lead_home_phone)) $phone = "Home Phone: $lead_home_phone\n";
    else if (!empty($lead_work_phone)) $phone = "Work Phone: $lead_work_phone\n";
    else if (!empty($lead_mobile_phone)) $phone = "Mobile Phone: $lead_mobile_phone\n";

    $dets = "Full name: $lead_title $lead_name\n";
    $dets .= "Address 1: $lead_address_1\n";
    $dets .= "Postcode: $lead_postcode\n";
    $dets .= "City/Town: $lead_city\n";
    $dets .= "State/Province: $lead_state\n";
    $dets .= "Country: $lead_country\n";
    if (!empty($phone)) $dets .= "$phone\n";
    $dets .= "Email Address: $lead_email";

    imagettftext($img, 8, 0, 50, 115, imagecolorallocate($img, 0, 0, 0), 'arial.ttf', "BOOKING FOR ".date('F j, Y', $the_date)."\nORDER ID # $order_id");
    imagettftext($img, 8, 0, 270, 115, imagecolorallocate($img, 0, 0, 0), 'arial.ttf', "$num_adults ADULTS $num_children CHILDREN\n$ticket_type");
    imagettftext($img, 8, 0, 50, 165, imagecolorallocate($img, 0, 0, 0), 'arial.ttf', $dets);
    imagettftext($img, 8, 0, 415, 165, imagecolorallocate($img, 0, 0, 0), 'arial.ttf', "Total: CZK $pay_total");

    $img_name = time().'.png';

    imagepng($img, "tickets/$img_name");

    $files = array();
    $files []= "tickets/$img_name";
    $files []= "tickets/brochure.jpg";

    // email fields: to, from, subject, and so on
    $from = "info@mysite.com"; 
    $subject ="Your Ticket"; 

    $message = "Booking Complete!";

    $headers = "From: $from";

    // boundary 
    $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

    // headers for attachment 
    $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 

    // multipart boundary 
    $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; 
    $message .= "--{$mime_boundary}\n";

    // preparing attachments
    for ($x=0; $x < count($files); $x++)
    {
        $file = fopen($files[$x],"rb");
        $data = fread($file,filesize($files[$x]));
        fclose($file);
        $data = chunk_split(base64_encode($data));
        $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . 
        "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" . 
        "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
        $message .= "--{$mime_boundary}\n";
    }

    // mail the emails with attachments
    mail('me@myemail.com', $subject, $message, $headers); 
}

How would I go about adding the 2 images into a PDF file, and then emailing that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:55:48+00:00Added an answer on June 9, 2026 at 3:55 am

    Take a look at a php pdf generation library like fpdf. I’ve used fpdf before and find it pretty easy and straight forward. Here is an example of how to use it from their site:

    <?php
    require('fpdf.php');
    
    class PDF extends FPDF
    {
    // Page header
    function Header()
    {
        // Logo
        $this->Image('logo.png',10,6,30);
        // Arial bold 15
        $this->SetFont('Arial','B',15);
        // Move to the right
        $this->Cell(80);
        // Title
        $this->Cell(30,10,'Title',1,0,'C');
        // Line break
        $this->Ln(20);
    }
    
    // Page footer
    function Footer()
    {
        // Position at 1.5 cm from bottom
        $this->SetY(-15);
        // Arial italic 8
        $this->SetFont('Arial','I',8);
        // Page number
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
    }
    }
    
    // Instanciation of inherited class
    $pdf = new PDF();
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->SetFont('Times','',12);
    for($i=1;$i<=40;$i++)
        $pdf->Cell(0,10,'Printing line number '.$i,0,1);
    $pdf->Output();
    ?>
    

    As you can see you basically just create a pdf, add a page, and then add images, text, tables etc. to that page and then you can output the pdf. In your case you would want to output it to some temp file, email that file, then probably delete that file to save room on your server (or delete them after some amount of days)

    Hopefully this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP-script originally developed on Ubuntu, which now has to run on
I have this PHP script which i'm grabbing images from a directory and displaying
I have a php script which is responsible for sending emails based on a
So I have a PHP script which takes in piped emails, appends a footer
I have a PHP script which has the source of an email. I aim
I have a PHP script through which I send HTML emails. I'm using a
I have a php script which saves the original image, then resizes it -
I have a PHP script which creates and listens on a port for connections
I have a PHP script which is generating buttons to each content schedule. The
I have a PHP search script which I've altered slightly and works well for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.