php - Emailing with Attachments -


trying accomplish php , i'm @ snag html in email fine boundary sections appear normal text , attachment wont attach.

$to = 'myemail@email.com'; $subject = 'contact submission'; $name       =   strip_tags($_post['name']); $emailto    =   strip_tags($_post['emailto']); $comments   =   strip_tags($_post['comments']); $attachment =   chunk_split(base64_encode(file_get_contents($_files['file']['tmp_name']))); $filename   =   $_files['file']['name'];  $boundary =md5(date('r', time()));   $headers  = 'mime-version: 1.0' . "\r\n"; $headers .= 'content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'from: noreply@emailcom' . "\r\n" .         'x-mailer: php/' . phpversion();  $comments="this multi-part message in mime format.  --_1_$boundary content-type: multipart/alternative; boundary=\"_2_$boundary\"  --_2_$boundary content-type: text/html; charset=iso-8859-1\" content-transfer-encoding: 7bit          <table width=\"600px\" cellpadding=\"0\" cellspacing=\"0\"style=\"\">           <tr valign=\"top\">             <th align=\"left\" style=\" font-family:verdana, geneva, sans-serif; color:#000; font-size:14px; padding-left:10px; line-height:32px\">contact submission</th>         </tr>         </table>         <br />          <table width=\"600\" cellpadding=\"0\" cellspacing=\"0\"style=\"border: 1px solid #000;\">           <tr valign=\"top\">             <td colspan=\"4\" style=\" font-family:verdana, geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; border-bottom: 1px solid #000;background:#ececec; line-height:32px;\" align=\"left\"><strong>contact information</strong></td>         </tr>           <tr valign=\"top\">             <td style=\" font-family:verdana, geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px; font-weight:bold\" align=\"right\" width=\"120\">name</td>             <td style=\" font-family:verdana, geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px;padding-left:40px;\">$name</td>             </tr>           <tr valign=\"top\">             <td style=\" font-family:verdana, geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px; font-weight:bold; background:#e6edf2;\" align=\"right\" width=\"120\">email</td>             <td style=\" font-family:verdana, geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px;background:#e6edf2;padding-left:40px;\">$emailto</td>           </tr>           <tr valign=\"top\">             <td style=\" font-family:verdana, geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px; font-weight:bold\" align=\"right\">comments</td>             <td style=\" font-family:verdana, geneva, sans-serif; color:#000; font-size:12px; padding-left:10px; line-height:32px;padding-left:40px;\" colspan=\"3\">$comments</td>           </tr>         </table>          --_2_$boundary--         --_1_$boundary         content-type: application/octet-stream; name=\"$filename\"          content-transfer-encoding: base64          content-disposition: attachment           $attachment         --_1_$boundary--";                  mail($to, $subject, $comments, $headers); 

any great needs changing/added/removed email keep html table , attach file

$to = "email";                     $subject = "your subject";                     $base = basename($file1); $file = fopen('file path','rb'); $size = filesize('file path'); $data = fread($file,$size); fclose($file); $data = chunk_split(base64_encode($data)); $message="<html><body>"; $message="<table border='1'>"; $message.="<tr><td colspan='3' align='center' style='color:#ffffff;font-size:large; background:#000000'>your information</td></tr>"; $message.="<tr><td style='font-weight:bold'>field 1</td><td style='font-weight:bold'>field 2</td></tr>"; $message.="</table>"; $message.="</body></html>";  //boundary $div = "==multipart_boundary_x".md5(time())."x"; //headers $head = "from: $email\n".     "mime-version: 1.0\n".     "content-type: multipart/mixed;\n".     " boundary=\"$div\""; //message $mess = "--$div\n".     "content-type: text/html; charset=\"iso-8859-1\"\n".     "content-transfer-encoding: 7bit\n\n".     "$message\n\n".     "--$div\n".     "content-type: application/octet-stream; name=\"$base\"\n".     "content-description: $base\n".     "content-disposition: attachment;\n".     " filename=\"$base\"; size=$size;\n".     "content-transfer-encoding: base64\n\n".     "$data\n\n".     "--$div\n"; $return = "-f$email";  mail($to,$subject,$mess,$head,$return); 

try code


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -