jimmyh Posted November 6, 2008 Share Posted November 6, 2008 Hi guys, second post in as mant days but last one was rather successful so i though i would ask you another question... I have devised some code to process a form and send an email with attachments. However the code will only send MS word or Excel Documents and i cant work out why, it would be really useful if someone could point me in the direction of allowing PDF and JPEG attachments as well. To be honest if the user could send any type of document this would be better than not being able to send PDF's Code is below and i look forward to your help again.. <?php if ($_POST['ProducingBroker'] == '') { $a1 = '<span style="color:red;">Producing Broker Omitted.</span>'; } else { $a1 = $_POST['ProducingBroker']; } if ($_POST['ClaimsHandlerName'] == '') { $a2 = '<span style="color:red;">Claims Handler Name Omitted.</span>'; } else { $a2 = $_POST['ClaimsHandlerName']; } if ($_POST['Email'] == '') { $a3 = '<span style="color:red;">Email Omitted.</span>'; } else { $a3 = $_POST['Email']; } if ($_POST['ContactNo'] == '') { $a4 = '<span style="color:red;">Contact No Omitted.</span>'; } else { $a4 = $_POST['ContactNo']; } if ($_POST['Policyholder'] == '') { $a5 = '<span style="color:red;">Policyholder Omitted.</span>'; } else { $a5 = $_POST['Policyholder']; } if ($_POST['InsuredName'] == '') { $a6 = '<span style="color:red;">Insured Name Omitted.</span>'; } else { $a6 = $_POST['InsuredName']; } if ($_POST['PolicyNumber'] == '') { $a7 = '<span style="color:red;">Policy Number Omitted.</span>'; } else { $a7 = $_POST['PolicyNumber']; } if ($_POST['DeclarationNumber'] == '') { $a8 = '<span style="color:red;">Declaration Number Omitted.</span>'; } else { $a8 = $_POST['DeclarationNumber']; } if ($_POST['InceptionDate'] == '') { $a9 = '<span style="color:red;">Inception Date Omitted.</span>'; } else { $a9 = $_POST['InceptionDate']; } if ($_POST['ExpiryDate'] == '') { $a10 = '<span style="color:red;">Expiry Date Omitted.</span>'; } else { $a10 = $_POST['ExpiryDate']; } if ($_POST['BindingAuthorityNumber'] == '') { $a11 = '<span style="color:red;">Binding Authority Number Omitted.</span>'; } else { $a11 = $_POST['BindingAuthorityNumber']; } if ($_POST['BindingAuthoritySection'] == '') { $a12 = '<span style="color:red;">Binding Authority Section Omitted.</span>'; } else { $a12 = $_POST['BindingAuthoritySection']; } if ($_POST['Coverholder'] == '') { $a13 = '<span style="color:red;">Coverholder Omitted.</span>'; } else { $a13 = $_POST['Coverholder']; } if ($_POST['DateofNotificationfromIsured'] == '') { $a14 = '<span style="color:red;">Date of Notification from Isured Omitted.</span>'; } else { $a14 = $_POST['DateofNotificationfromIsured']; } $message= ' <h1>New Claim Notification</h1> <table cellspacing="1" cellpadding="3" border="2"> <tr> <th><FONT COLOR="#336699">Details Required</font></th> <th><FONT COLOR="#336699">Data entered By Producing Broker or Agent</font></th> <th></th> <th></th> <th><FONT COLOR="#336699">For Administrative Use Only</font></th> </tr> <TR><TD><b><FONT COLOR="#336699">Producing Broker / Agent Name</font></b></TD><TD>'.$a1.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Claims Handler Name</font></b></TD><TD>'.$a2.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Email</font></b></TD><TD>'.$a3.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Contact Number</font></b></TD><TD>'.$a4.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Policyholder</font></b></TD><TD>'.$a5.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Insured Name</font></b></TD><TD>'.$a6.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Policy Number</font></b></TD><TD>'.$a7.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Declaration Number</font></b></TD><TD>'.$a8.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Inception Date</font></b></TD><TD>'.$a9.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Expiry Date</font></b></TD><TD>'.$a10.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Binding Authority Number</font></b></TD><TD>'.$a11.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Binding Authority Section</font></b></TD><TD>'.$a12.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Coverholder</font></b></TD><TD>'.$a13.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Date of Notification from Isured</font></b></TD><TD>'.$a14.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Date of Notification from Isured</font></b></TD><TD>'.$a14.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD><b><FONT COLOR="#336699">Date of Notification from Isured</font></b></TD><TD>'.$a14.'</TD><TD></TD><TD></TD><TD BGCOLOR="#FFFFCC"> </TD></TR> <TR><TD colspan="5"></TD></TR> <TR><TD colspan="5"></TD></TR> <TR><TD colspan="5"></TD></TR> <TR><TD colspan="5"></TD></TR> <TR><TD colspan="5"></TD></TR> <TR><TD colspan="5"></TD></TR> <TR><td><b>Claim Receipt Sign Off:</b></TD><td colspan="4"><B>Sign Here:</B></TD></TR> </table> '; // MAIL SUBJECT $subject = "Claims notification Form"; // TO MAIL ADDRESS $to="jhinds@iprins.com"; /* // MAIL HEADERS $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\n"; $headers .= "From: '$a3'\r\nReply-To: '$a3'"; */ //Normal headers $headers = "From: '$a3'\r\nReply-To: '$a3'"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/mixed; "; $headers .= "boundary=".$num."\r\n"; $headers .= "--$num\r\n"; // With message $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n"; $headers .= "Content-Transfer-Encoding: 8bit\r\n"; $headers .= "".$message."\n"; $headers .= "--".$num."\n"; foreach($_FILES as $userfile) { $tmp_name = $userfile['tmp_name']; $type = $userfile['type']; $name = $userfile['name']; $size = $userfile['size']; if (file_exists($tmp_name)) { if(is_uploaded_file($tmp_name)) { $file = fopen($tmp_name,'rb'); $data = fread($file,filesize($tmp_name)); fclose($file); $data = chunk_split(base64_encode($data)); } $message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; } } $message.="--{$mime_boundary}--\n";; // SEND MAIL @mail($to, $subject, $message, $headers); echo ' <h1><B><I><U>New Claim Notification Sent <FONT COLOR=RED>SUCCESSFULLY</FONT></h1></B></I></u> <table cellspacing="5" cellpadding="5" border="2" BORDERCOLOR="#336699"> <tr> <th BGCOLOR="#FFFFCC"><FONT COLOR="#336699">Details Required</font></th> <th BGCOLOR="#FFFFCC"><FONT COLOR="#336699">Data entered By Producing Broker or Agent</font></th> </tr> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Producing Broker / Agent Name</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a1.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Claims Handler Name</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a2.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Email</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a3.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Contact Number</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a4.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Policyholder</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a5.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Insured Name</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a6.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Policy Number</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a7.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Declaration Number</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a8.'</TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Inception Date</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a9.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Expiry Date</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a10.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Binding Authority Number</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a11.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Binding Authority Section</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a12.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Coverholder</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a13.'</TD></TR> <TR><TD BGCOLOR="#FFFFCC"><b><FONT COLOR="#336699">Date of Notification from Isured</font></b></TD><TD BGCOLOR="#FFFFCC">'.$a14.'</TD></TR> </table> <BR> <BR> <B><I>You may wish to print this page for your records the mail has been sent.</b></i> '; ?> Quote Link to comment https://forums.phpfreaks.com/topic/131614-email-wont-attach-pdf-only-word-docs-and-i-cant-see-why/ Share on other sites More sharing options...
JonnoTheDev Posted November 6, 2008 Share Posted November 6, 2008 Is the file larger than the max upload size set in your php.ini file? Also use a proper mime email library such as PEAR's Mail::Mime for sending email attachments as opposed to using the default mail() function Quote Link to comment https://forums.phpfreaks.com/topic/131614-email-wont-attach-pdf-only-word-docs-and-i-cant-see-why/#findComment-683618 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.