AddPage(); // Set the image $pdf->Image('@' . base64_decode($imgData), 15, 15, 180, 0, 'PNG'); $pdfData = $pdf->Output($invoiceNumber. '.pdf', 'S'); // Send email with PDF attachment $subject = "INVOICE: " . $invoiceNumber ; $toEmail = "info@blackhoundenterprises.com"; $BH = "Blackhound Architecture & Rendering"; $clientname = $_POST['clientName']; $clientemail = $_POST['clientEmail']; $createdBy = $_POST['createdBy']; $projectNumber = $_POST['projectNumber']; $clientId = $_POST['clientId']; $projectName = $_POST['projectName']; $myArray1 = explode(' ', $clientname); $myArray2 = explode(' ', $createdBy); $message = "

" . "Hi " . $myArray1[0] . ","; $message .= "

See latest invoice attached for ". $projectName . ".

"; $message .= "Tracking your project:
"; $message .= "Click here

"; $message .= "See invoice(s):
"; $message .= "Click here

"; $message .= "If you have any questions, feel free to give me a call.

"; $message .= "Thank you for your business." . "

"; $message .= "Kind regards,"; // Specify the file path $file_pathH = "BH_HG.txt"; // Change this to your file's path $file_contentsH = file_get_contents($file_pathH); $tempImagePath = ""; if ("Dewald" == $myArray2[0]){ //$message .= "

Image"; //$imageData = base64_decode($file_contentsD); $tempImagePath = $myArray2[0] . '.png'; //file_put_contents($tempImagePath, $imageData); $businessEmail = "dewald@blackhoundenterprises.com"; } else { //$message .= "

Image"; $businessEmail = "hannes@blackhoundenterprises.com"; //$imageData = base64_decode($file_contentsH); $tempImagePath = $myArray2[0] . '.png'; //file_put_contents($tempImagePath, $imageData); } $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = SMTP::DEBUG_SERVER; $mail->isSMTP(); $mail->Host = 'mail.blackhoundenterprises.com'; $mail->SMTPAuth = true; $mail->Username = 'info@blackhoundenterprises.com'; $mail->Password = 'r0N=mrp%l122'; $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; $mail->Port = 465; // Email content $mail->setFrom('info@blackhoundenterprises.com', 'Blackhound | Architecture & Rendering'); // Email content $mail->addAddress($businessEmail); //$clientemail $mail->addStringAttachment($pdfData, $invoiceNumber . '.pdf', 'base64', 'application/pdf'); $mail->addEmbeddedImage($tempImagePath, 'signature', $tempImagePath); $message .= '

'; $mail->AltBody = "Hi " . $myArray1[0]. ","; $mail->isHTML(true); $mail->Subject = $subject; $mail->Body = $message; $mail->send(); echo 'Email sent successfully'; } catch (Exception $e) { echo 'Email could not be sent. Error: ', $mail->ErrorInfo; } } ?>