josephnwachukwu Posted June 9, 2008 Share Posted June 9, 2008 Hi everyone. Im not sure if its possible to send an mp3 attachment using mail(); I cannot get the mp3 to add as an attachment but rather as a large string of text in the email. Can anyone help? Link to comment https://forums.phpfreaks.com/topic/109348-send-an-mp3-attachment-using-mail/ Share on other sites More sharing options...
tippy_102 Posted June 9, 2008 Share Posted June 9, 2008 Are you base64 encoding the file, then setting the Content-Transfer-Encoding: base64 ? Link to comment https://forums.phpfreaks.com/topic/109348-send-an-mp3-attachment-using-mail/#findComment-560891 Share on other sites More sharing options...
josephnwachukwu Posted June 9, 2008 Author Share Posted June 9, 2008 yeah i am here is my code. $fileatt = "audio/" . $Location1; // Path to the file $fileatt_type = "(audio/mpeg)"; // File Type $fileatt_name = $Name1; // Filename that will be used for the file as the attachment //$email_from = ""; // Who the email is from //$headers = "From: ".$email_from; $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $data = chunk_split(base64_encode($data)); $message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; //$to = $_POST['number'] .'@' . $_POST['ctype']; $to = "[email protected]"; $headers = 'From: ' . $site_email . "\r\n" . 'Reply-To: ' . $site_email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Your audio From my site"; //$message .= $Name . ' ' . $Artist; if ( mail($to, $subject, $message, $headers ) ) { $msg = 'Your audio has been sent.'; } else { $error = 'There was an error sending your audio please try again'; } } any ideas? Link to comment https://forums.phpfreaks.com/topic/109348-send-an-mp3-attachment-using-mail/#findComment-560917 Share on other sites More sharing options...
josephnwachukwu Posted June 9, 2008 Author Share Posted June 9, 2008 Anybody out there, any ideas? Link to comment https://forums.phpfreaks.com/topic/109348-send-an-mp3-attachment-using-mail/#findComment-561389 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.