Hi need help with my code, its not sending any attachment to any document, i have been struggling for almost a week no with no progress at all. This code does not work 100% because it only send an empty email with no header and attachments.
//code to send multiple attachment and email with pdf
<?php
/** Mail with attachment */
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $bcc, $subject, $message){
$uid = md5(uniqid(time()));
$mime_boundary = "==Multipart_Boundary_x{$uid}x";
$header = "gcobani.mkontwana@agilelimitless.org.za: ".$from_name." <".$from_mail.">\r\n";
$header .= "ggcobani@gmail.com: ".$bcc."\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$mime_boundary."\r\n";
$header .= "Content-type:text/html; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= nl2br($message)."\r\n\r\n";
$header .= "--".$mime_boundary."\r\n";
foreach($filename as $k=>$v){
$file = $path.$v;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$header .= "Content-Type: application/octet-stream; name=\"".$v."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$v."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$mime_boundary."--"."\r\n";
}
$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'];
$send = mail($to, $subject, $body, $headers);
// 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();
}
}
?>