[email protected] Posted July 26, 2009 Share Posted July 26, 2009 Dear all, I have downloaded a php script for send html email with attachment but the script is sending the attachment without html message. Can you please take a look into script. I think it is some header problem. Please help me ASAP. Thanks in advance. <?php $strname=ucfirst($_REQUEST["strname"]); $straddress=ucfirst($_REQUEST["straddress"]); $strcity=ucfirst($_REQUEST["strcity"]); $strstate=ucfirst($_REQUEST["strstate"]); $phone=$_REQUEST["strno"]; if($phone != ""){ $strno=$phone; } else { $strno="-"; } $stremail=$_REQUEST["stremail"]; $strcomments=ucfirst($_REQUEST["strcomments"]); $filename=$_FILES["strresume"]["name"]; $filetype=$_FILES["strresume"]["type"]; $filesize=$_FILES["strresume"]["size"]; $filetemp=$_FILES["strresume"]["tmp_name"]; echo $filename; echo $filesize; echo $filetype; echo $filetemp; if($filetype=="application/octet-stream" or $filetype=="text/plain" or $filetype=="application/msword") { $message= ' <html><body> <table cellspacing="0" cellpadding="8" border="0" width="400"> <tr> <td colspan="2"></td> </tr> <tr bgcolor="#eeeeee"> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Name</strong></td> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strname.'</td> </tr> <tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> <tr bgcolor="#eeeeee"> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Address</strong></td> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$straddress.'</td> </tr> <tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> <tr bgcolor="#eeeeee"> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>City</strong></td> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strcity.'</td> </tr> <tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> <tr bgcolor="#eeeeee"> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>State</strong></td> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strstate.'</td> </tr> <tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> <tr bgcolor="#eeeeee"> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Contact No.</strong></td> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strno.'</td> </tr> <tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> <tr bgcolor="#eeeeee"> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Email</strong></td> <td style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$stremail.'</td> </tr> <tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> <tr bgcolor="#eeeeee"> <td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;"><strong>Comments</strong></td> </tr> <tr bgcolor="#eeeeee"> <td colspan="2" style="font-family:Verdana, Arial; font-size:11px; color:#333333;">'.$strcomments.'</td> </tr> <tr><td colspan="2" style="padding:0px;"><img src="images/whitespace.gif" alt="" width="100%" height="1" /></td></tr> </table> </body></html> '; // MAIL SUBJECT $subject = "Mail with doc file attachment"; // TO MAIL ADDRESS $to="[email protected]"; // MAIL HEADERS /* $headers = "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\n"; $headers .= "From: Name <[email protected]>\n"; */ // MAIL HEADERS with attachment if(!($fp = fopen($filetemp, 'rb'))) echo "File failed to open"; //$fp = fopen($filetemp, "rb"); $file = fread($fp, $filesize); $file = chunk_split(base64_encode($file)); $num = md5(time()); //Normal headers $headers = "From: Name<[email protected]>\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/mixed; "; $headers .= "boundary=".$num."\r\n"; $headers .= "--$num\r\n"; // This two steps to help avoid spam $headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n"; $headers .= "X-Mailer: PHP v".phpversion()."\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"; // Attachment headers $headers .= "Content-Type:".$strresume_type." "; $headers .= "name=\"".$strresume_name."\"r\n"; $headers .= "Content-Transfer-Encoding: base64\r\n"; $headers .= "Content-Disposition: attachment; "; $headers .= "filename=\"".$strresume_name."\"\r\n\n"; $headers .= "".$file."\r\n"; $headers .= "--".$num."--"; // SEND MAIL mail($to, $subject, $message, $headers); fclose($fp); echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#333333; font-weight:bold">Attachment has been sent Successfully.<br /></font>'; } else { echo '<font style="font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold">Wrong file format. Mail was not sent.</font>'; //echo "<script>window.location.href='careers.html';</script>"; } ?> Link to comment https://forums.phpfreaks.com/topic/167465-php-send-html-email-with-attachment-problem/ Share on other sites More sharing options...
mmarif4u Posted July 26, 2009 Share Posted July 26, 2009 Please use code blocks represented as # button in above editor while writing. Easy to understand the code. Link to comment https://forums.phpfreaks.com/topic/167465-php-send-html-email-with-attachment-problem/#findComment-883030 Share on other sites More sharing options...
[email protected] Posted July 26, 2009 Author Share Posted July 26, 2009 I dnt know how to use the code blocks. I am new to PHP also. Can you please do a favor and look into code. I think its only some header problem. Thanks Link to comment https://forums.phpfreaks.com/topic/167465-php-send-html-email-with-attachment-problem/#findComment-883286 Share on other sites More sharing options...
patrickmvi Posted July 27, 2009 Share Posted July 27, 2009 You should try using PHPMailer instead. You can get it here: http://sourceforge.net/projects/phpmailer/ Link to comment https://forums.phpfreaks.com/topic/167465-php-send-html-email-with-attachment-problem/#findComment-883895 Share on other sites More sharing options...
[email protected] Posted July 27, 2009 Author Share Posted July 27, 2009 Is any working sample of php mailer? I have but not working. Link to comment https://forums.phpfreaks.com/topic/167465-php-send-html-email-with-attachment-problem/#findComment-884083 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.