Zen Cart Logo
Forums / Customization from the Admin / pdf.invoice file sent with the order confirmation email

pdf.invoice file sent with the order confirmation email

Views: 1,617

Results 1 to 1 of 1
3 Feb 2014, 5:53 AM
#1
advisers_australia avatar

advisers_australia

New Zenner

Join Date:
Jan 2014
Location:
Australia
Posts:
39
Plugin Contributions:
0

pdf.invoice file sent with the order confirmation email

Hi

I have been looking through the posts but I have not found a solution to creating a pdf invoice file that is sent with the order confirmation email.

An old post referred to the following code. Has anyone had any success with installing the code into Zencart? Thanks in advance for your suggestions . Justin

// once there are no errors, as soon as the customer hits the submit button, it needs to send an email to the staff with the customer information
$msg = "Name: " .$_POST['name'] . "\n"
."Email: " .$_POST['email'] . "\n"
."Phone: " .$_POST['telephone'] . "\n"
."Number Of Guests: " .$_POST['numberOfGuests'] . "\n"
."Date Of Reunion: " .$_POST['date'];
$staffEmail = "staffemail";

    mail($staffEmail, "You have a new customer", $msg); // using the mail php function to send the email. mail(to, subject line, message)

    //once the customer submits his/her information, he/she will receive a thank you message attach with a pdf file.
    // creating a pdf file
    $pdf_filename = tempnam(sys_get_temp_dir(), "pdf");
    $pdf=new FPDF();
    $pdf->AddPage();
    $pdf->SetFont("Arial", "B", 16);
    $pdf->Cell(40, 10, "Title");
    $pdf->Ln();
    $pdf->SetFont("Arial", "", 12);
    $pdf->Cell(15, 10, "Name:");
    $pdf->SetFont("Arial", "I", 12);
    $pdf->Cell(15, 10, $_POST['name']);
    $pdf->Ln();
    $pdf->SetFont("Arial", "", 12);
    $pdf->Cell(15, 10, "Email:");
    $pdf->SetFont("Arial", "I", 12);
    $pdf->Cell(15, 10, $_POST['email']);
    $pdf->Ln();
    $pdf->SetFont("Arial", "", 12);
    $pdf->Cell(15, 10, "Phone:");
    $pdf->SetFont("Arial", "I", 12);
    $pdf->Cell(15, 10, $_POST['telephone']);
    $pdf->Ln();
    $pdf->SetFont("Arial", "", 12);
    $pdf->Cell(40, 10, "Number of Guests:");
    $pdf->SetFont("Arial", "I", 12);
    $pdf->Cell(40, 10, $_POST['numberOfGuests']);
    $pdf->Ln();
    $pdf->SetFont("Arial", "", 12);
    $pdf->Cell(40, 10, "Date Of Reunion:");
    $pdf->SetFont("Arial", "I", 12);
    $pdf->Cell(40, 10, $_POST['date']);
    // if file doesn't exists or if it is writable, create and save the file to a specific place 
    if(!file_exists($pdf_filename) || is_writable($pdf_filename)){
        $pdf->Output($pdf_filename, "F");
    } else { 
        exit("Path Not Writable");
    }

    // using the phpmailer class
    // create a new instance called $mail and use its properties and methods.
    $mail = new PHPMailer();
    $staffEmail = "staffemail";
    $mail->From = $staffEmail;
    $mail->FromName = "name";
    $mail->AddAddress($_POST['email']);
    $mail->AddReplyTo($staffEmail, "name");

    $mail->AddAttachment($pdf_filename);
    $mail->Subject = "PDF file attachment";

    $mail->Body = "message!";

    // if mail cannot be sent, diplay error message
    //if(!$mail->Send()){
        //echo "<div id=\"mailerrors\">Message could not be sent</div>";
        //echo "<div id=\"mailerrors\">Mailer Error: " . $mail->ErrorInfo . "</div>";
    //} else { // else...if mail is sent, diplay sent message
        //echo "<div id=\"mailerrors\">Message sent</div>";
    //}

    // delete the temp file
    unlink($pdf_filename);
}

}