DEV Community

Gcobani Mkontwana
Gcobani Mkontwana

Posted on

PDF is not opening using php mail function

Hi Team

I need help with my code below, i am sending an email attachment has a pdf document. But the problem when i view it its not opening need help around it.

// application.php


Enter fullscreen mode Exit fullscreen mode

<?php

$filenameee = $_FILES['id']['name'];
$fileName = $_FILES['id']['temp_name'];
$amount =$_REQUEST['amount'];
$purpose =$_REQUEST['purpose'];
$voucher =$_REQUEST['voucher'];
$gender =$_REQUEST['gender'];
$fname =$_REQUEST['fname'];
$lname =$_REQUEST['lname'];
$title =$_REQUEST['title'];
$typeID =$_REQUEST['typeID'];
$email =$_REQUEST['email'];
$number =$_REQUEST['number'];
$maritalstatus =$_REQUEST['maritalstatus'];
$street1 =$_REQUEST['street1'];
$street2 =$_REQUEST['street2'];
$town =$_REQUEST['town'];
$province =$_REQUEST['province'];
$code =$_REQUEST['code'];
$propertyownership =$_REQUEST['propertyownership'];
$placeofwork =$_REQUEST['placeofwork'];
$jobtitle =$_REQUEST['jobtitle'];
$jobstreet=$_REQUEST['jobstreet'];
$jobstreet2 =$_REQUEST['jobstreet2'];
$jobtown =$_REQUEST['jobtown'];
$worknumber =$_REQUEST['worknumber'];
$jobprovince =$_REQUEST['jobprovince'];
$jobcode =$_REQUEST['jobcode'];
$income =$_REQUEST['income'];
$bankname=$_REQUEST['bankname'];
$branchname =$_REQUEST['branchname'];
$accountno =$_REQUEST['accountno'];
$accounttype =$_REQUEST['accounttype'];
$signature =$_REQUEST['signature'];
$bankstatement =$_REQUEST['bankstatement'];
$payslip=$_REQUEST['payslip'];

$message = "Name: ". $fname . $lname . "\r\n Email: " . $email . "\r\n Cell Number: " . $number . "\r\n Monthly Income: " . $income . "\r\n Loan Amount: " . $amount . "\r\n Town:" . $town;

$subject ="Application Form";
$fromname ="ACI FINANCE";
$fromemail = $email; //if u dont have an email create one on your cpanel
$mailto = 'Ongeziwe1998@gmail.com'; //the email which u want to recv this email
$content = file_get_contents($filenameee);
$content = chunk_split(base64_encode($content));

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (RFC)
$eol = "\r\n";

// main header (multipart mandatory)
Enter fullscreen mode Exit fullscreen mode

$headers = "From: ".$fromname." <".$fromemail.">" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
$headers .= "This is a MIME encoded message." . $eol;

$logo = 'img/logo.png';
$link = '#';

$body = "<!DOCTYPE html><html lang='en'><head><meta charset='UTF-8'><title>Express Mail</title></head><body>";
$body .= "<table style='width: 100%;'>";
$body .= "<thead style='text-align: center;'><tr><td style='border:none;' colspan='2'>";
$body .= "<a href='{$link}'><img src='{$logo}' alt=''></a><br><br>";
$body .= "</td></tr></thead><tbody><tr>";
$body .= "<td style='border:none;'><strong>Name:</strong> {$fname} {$lname}</td>";
$body .= "<td style='border:none;'><strong>Email:</strong> {$from}</td>";
$body .= "</tr>";
$body .= "<tr><td style='border:none;'><strong>CellNumber:</strong> {$number}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td style='border:none;'><strong>Loan Amount:</strong> {$amount}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td style='border:none;'><strong>Monthly income:</strong> {$income}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td style='border:none;'><strong>Town:</strong> {$town}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td style='border:none;'><strong>Upload bankstatement </strong> {$bankstatement}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td style='border:none;'><strong>Upload payslip:</strong> {$payslip}</td></tr>";
$body .= "<tr><td></td></tr>";
$body .= "<tr><td colspan='2' style='border:none;'><strong></strong> </td></tr>";
// message
Enter fullscreen mode Exit fullscreen mode

$body = "--" . $separator . $eol;
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $eol;
$body .= $message . $eol;
// attachment
$body .= "--" . $separator . $eol;
$body .= "Content-Type: application/pdf; name=\"" . $filenameee . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment" . $eol;
$body .= $content . $eol;
$body .= "--" . $separator . "--";
$readfile.= "$filenameee";

$body .= "";

$body .= "

Top comments (0)