brooksh Posted August 27, 2017 Share Posted August 27, 2017 My code works, unless I send it to gmail, then the attachment doesn't show up, and the body shows: This is a multi-part message in MIME format. I'm assuming my headers are incorrect. $from = stripslashes($from_name)."<".stripslashes($from_email).">"; $uniqid = md5(uniqid(time())); $boundary = "--==_mimepart_".$uniqid; $headers = "From: ".$from."\n". 'Subject: '.$subject."\n". 'Reply-to: '.$from_email."\n". 'Return-Path: '.$from_email."\n". 'Message-ID: <'.$uniqid.'@'.$domain.">\n". 'Date: '.date("r", strtotime("now"))."\n". 'Mime-Version: 1.0'."\n". 'Content-Type: text/html;'."\n". ' boundary=PHP-mixed-'.$boundary.";\n". ' charset=UTF-8'."\n". 'X-Mailer: PHP/' . phpversion(); $headers .= 'Content-Type: multipart/mixed; boundary="'.$uniqid.'"\r\n\r\n'; $headers .= 'This is a multi-part message in MIME format.\r\n'; $headers .= '--'.$uniqid.'\r\n'; $headers .= 'Content-type:text/html; charset=iso-8859-1\r\n'; $headers .= 'Content-Transfer-Encoding: 7bit\r\n\r\n'; $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; $message = $html; $count_uploaded_files = count( $uploaded_files['attachments']['tmp_name'] ); if($uploaded_files['attachments']['name'][0] != ""){ $headers .= "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; $message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; for( $i = 0; $i < $count_uploaded_files; $i++ ) { $tmp_name = $uploaded_files['attachments']['tmp_name'][$i]; $type = $uploaded_files['attachments']['type'][$i]; $name = $uploaded_files['attachments']['name'][$i]; $size = $uploaded_files['attachments']['size'][$i]; 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"; } } $headers .= "--".$uniqid."--"; $message.="--{$mime_boundary}--\n"; }//end files sent mail($to_addresses, $subject, $message, $headers); Quote Link to comment Share on other sites More sharing options...
requinix Posted August 27, 2017 Share Posted August 27, 2017 You've messed up the email headers. Don't try to do this yourself. Use something like PHPMailer instead. Quote Link to comment Share on other sites More sharing options...
skptricks Posted August 27, 2017 Share Posted August 27, 2017 (edited) check out the link : https://goo.gl/Dof1TA Edited August 27, 2017 by requinix including actual link Quote Link to comment Share on other sites More sharing options...
brooksh Posted August 27, 2017 Author Share Posted August 27, 2017 check out the link : https://goo.gl/Dof1TA Not helpful at all. I'm using mail() not gmail SMTP. Also I'm asking about attachments. Quote Link to comment Share on other sites More sharing options...
requinix Posted August 27, 2017 Share Posted August 27, 2017 Not helpful at all.Not even the example that shows how to use PHPMailer? That sounds helpful to me. Though I'm not thrilled about the blog spam. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 27, 2017 Share Posted August 27, 2017 Doing it as suggested with PHPMailer will make your life much more enjoyable. By the time you (possibly) figure out how to do this with the php mail function, you could have downloaded it and installed the package and sent your email successfully. Really. Quote Link to comment Share on other sites More sharing options...
brooksh Posted August 27, 2017 Author Share Posted August 27, 2017 I understand the phpmailer is a good program, but I'm doing something else. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 27, 2017 Share Posted August 27, 2017 Then that's your problem, isn't it? The code you've posted is wrong on every single level. Even if you manage to find somebody who's masochistic enough to debug this mess, that doesn't get you anywhere. You're just polishing a turd. That's why you've been offered a valid approach which actually solves the underlying problem. You don't want that? Then enjoy the code you have. Quote Link to comment Share on other sites More sharing options...
brooksh Posted August 27, 2017 Author Share Posted August 27, 2017 (edited) Sorry master PHP script writer. Glad there are jerks like you on this forum. Then that's your problem, isn't it? The code you've posted is wrong on every single level. Even if you manage to find somebody who's masochistic enough to debug this mess, that doesn't get you anywhere. You're just polishing a turd. That's why you've been offered a valid approach which actually solves the underlying problem. You don't want that? Then enjoy the code you have. Edited August 27, 2017 by brooksh Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 28, 2017 Share Posted August 28, 2017 I don't understand what you meant by your statement - "I'm doing something else". What does that even mean?? And your snarky comment to Jacques is totally uncalled for. You are being given heartfelt good advice to avoid the out-date and simplistic PHP mail() function for something that is a recognized leader in mail programs and you give back nothing. If you don't want good advice and don't want to explain why you don't like it, then why do you even seek out advice from people like us? I give you -1 for your attitude. Quote Link to comment Share on other sites More sharing options...
requinix Posted August 28, 2017 Share Posted August 28, 2017 If you want to do it yourself, fine. But you have to learn about the proper syntax for multipart messages in emails - I suggest the RFC. For real. Not just make it up as you go. Because I'm very surprised what you produced there works in any email client. Quote Link to comment 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.