Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team

I need some help with my script, i am only managing to send pdf attachment but cant be able to view it as a document. Please assist me and guide me, thank you.

What I have tried:

<?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'];
   $usermessage = $_POST['message'];
   
   $message ="Name = ". $fname . "\r\n Email = " . $email . "\r\n Surname = " . $lname . "\r\n Message =" . $usermessage;
   
   $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)
   $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;'>Name: {$fname} {$lname}</td>";
	$body .= "<td style='border:none;'>Email: {$from}</td>";
	$body .= "</tr>";
	$body .= "<tr><td style='border:none;'>CellNumber: {$number}</td></tr>";
	$body .= "<tr><td></td></tr>";
	$body .= "<tr><td style='border:none;'>Loan Amount: {$amount}</td></tr>";
	$body .= "<tr><td></td></tr>";
	$body .= "<tr><td style='border:none;'>Monthly income: {$income}</td></tr>";
	$body .= "<tr><td></td></tr>";
	$body .= "<tr><td style='border:none;'>Town: {$town}</td></tr>";
	$body .= "<tr><td></td></tr>";
	$body .= "<tr><td style='border:none;'>Upload bankstatement  {$bankstatement}</td></tr>";
	$body .= "<tr><td></td></tr>";
	$body .= "<tr><td style='border:none;'>Upload payslip: {$payslip}</td></tr>";
	$body .= "<tr><td></td></tr>";
	$body .= "<tr><td colspan='2' style='border:none;'> </td></tr>";
	// message
  $body = "--" . $separator . $eol;
  $body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol;
  $body .= "Content-Transfer-Encoding: 8bit" . $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 . "--";
$body .= "</tbody></table>";
	
$body .= "</body></html>";

//SEND Mail
 if (mail($mailto, $subject, $body, $headers)) {
echo "mail send ... OK"; // do what you want after sending the email
 } else {
echo "mail send ... ERROR!";
print_r( error_get_last() );
 }
    
    $send = mail($to, $subject, $body, $headers); 
    
   $amount  =$_POST['amount'];
   $purpose =$_POST['purpose'];
   $voucher =$_POST['voucher'];
   $gender =$_POST['gender'];
   $fname =$_POST['fname'];
   $lname =$_POST['lname'];
   $title =$_POST['title'];
   $typeID =$_POST['typeID'];
   $email =$_POST['email'];
   $number =$_POST['number'];
   $maritalstatus =$_POST['maritalstatus'];
   $street1 =$_POST['street1'];
   $street2 =$_POST['street2'];
   $town =$_POST['town'];
   $province =$_POST['province'];
   $code =$_POST['code'];
   $propertyownership =$_POST['propertyownership'];
   $placeofwork =$_POST['placeofwork'];
   $jobtitle =$_POST['jobtitle'];
   $jobstreet=$_POST['jobstreet'];
   $jobstreet2 =$_POST['jobstreet2'];
   $jobtown =$_POST['jobtown'];
   $worknumber =$_POST['worknumber'];
   $jobprovince =$_POST['jobprovince'];
   $jobcode =$_POST['jobcode'];
   $income =$_POST['income'];
   $bankname=$_POST['bankname'];
   $branchname =$_POST['branchname'];
   $accountno =$_POST['accountno'];
   $accounttype =$_POST['accounttype'];
   $signature =$_POST['signature'];
   $bankstatement =$_POST['bankstatement'];
   $payslip=$_POST['payslip'];
   
   
   
   // Connect to database
   
   $conn = new mysqli('localhost','acifinan_acifinan','Finance_01','acifinan_acifinanc');
   if ($conn->connect_error)
   {die('Connection Failed:'.$conn-> connect_error); }
   else 
  {
      $stmt= $conn->prepare("insert into application(amount, purpose, voucher, gender, fname, lname, title, typeID, email, number, maritalstatus, street1, street2, town, province, code, propertyownership, placeofwork, jobtitle, jobstreet, jobstreet2, jobtown, worknumber, jobprovince, jobcode, income, bankname, branchname, accountno, accounttype, signature, id, bankstatement, payslip) values (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?)");
      $stmt-> bind_param("ssssssssssssssssssssssssssssssssss" , $amount,$purpose,$voucher,$gender,$fname,$lname,$title,$typeID,$email,$number,$maritalstatus,$street1,$street2,$town,$province,$code,$propertyownership,$placeofwork,$jobtitle,$jobstreet,$jobstreet2,$jobtown,$worknumber,$jobprovince,$jobcode,$income,$bankname,$branchname,$accountno,$accounttype,$signature,$id,$bankstatement,$payslip);
      $stmt->execute();
      echo "Submitted Successfully";
      $stmt->close();
      $conn->close();
  
      
  }
    
?>
Posted
Updated 8-Mar-23 1:15am

1 solution

See view pdf in php - Google Search[^]. Please try doing your own research first.
 
Share this answer
 
Comments
Gcobani Mkontwana 8-Mar-23 7:18am    
@Richard MacCutchan, thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900