contra10 Posted October 3, 2009 Share Posted October 3, 2009 I'm having trouble with emails and php when it sends to a hotmail account everything shows but in gmail or yahoo accout it shows a download link for a no name file, the actual writing doesn't show <?php $to = ($email); $subject = "Verification"; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); $from = "admin@url.com"; $headers = "From: $from"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <div style="width:800px; height:400px; border:4px dashed grey; "> <table bgcolor="black" width="800" > <tr><td> <img src="http://www.url.com/images/logo.png"/><br><br><font size="12" color="white">You have sucessfully become a member</font><br> <?php echo"<p align='center'>"; echo"<table background='#6D6D6D' width='700' height='250'>"; echo "<tr><td><b><font color='white'>Dear, $usere <br><br> To complete your activation please click on the \"Verify\" link below."; echo "<b>To contine to verify your account please follow the link </b><a href='http://www.url.com/verify.php?v=$usere' target='_blank'><font color='red'>Verify Account</font></a>"; echo"</font></td></tr>"; echo "</table>"; echo"</p>"; ?> </td></tr> <tr><td align="center"><font size="1" color="white">Copyright 2009</font></td></tr> </table> </div> --PHP-alt-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( "$to", $subject, $message, $headers ); ?> Quote Link to comment Share on other sites More sharing options...
contra10 Posted October 3, 2009 Author Share Posted October 3, 2009 i jus dun get why it shows as a file download in a gmail email Quote Link to comment Share on other sites More sharing options...
kristenju Posted October 5, 2009 Share Posted October 5, 2009 actually.. mine worked when it was only html with google.. but ever since i added the multipart/alternative ... with google, it doesn't display in html, but in plain text.. sigh i tried using ob function too.. but it doesn't work well. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 5, 2009 Share Posted October 5, 2009 Go to my sig link it all about headers pal. add this as a extras header. <?php $headers = 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; ?> Quote Link to comment Share on other sites More sharing options...
corbin Posted October 5, 2009 Share Posted October 5, 2009 Go to my sig link it all about headers pal. add this as a extras header. <?php $headers = 'X-Mailer: PHP/' . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; ?> That doesn't help with multipart headers at all. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 5, 2009 Share Posted October 5, 2009 This works been told <?php $from = "From: <martin.thorburn@tiscali.co.uk>"; $fileatt = "PDF/"; $fileatt .= $filename; $fileatttype = "application/pdf"; $fileattname .= $filename; $headers = "From: $from"; $messageletter = "what ever text you would like in here. It can be huge and use \n to start a new line within the email"; $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" . $messageletter . "\n\n"; $data = chunk_split( base64_encode( $data ) ); $message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatttype};\n" . " name=\"{$fileattname}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileattname}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; if( mail( $to, $subject, $message, $headers ) ) { echo "<p>The email was sent.</p>"; } else { echo "<p>There was an error sending the mail.</p>"; } ?> Quote Link to comment Share on other sites More sharing options...
kristenju Posted October 6, 2009 Share Posted October 6, 2009 I tried. It doesn't work with gmail still... Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 6, 2009 Share Posted October 6, 2009 use this as added header info. gmail way.... $headers = "From: info@website.com\nReply-To: info@website.com"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; Quote Link to comment Share on other sites More sharing options...
kristenju Posted October 6, 2009 Share Posted October 6, 2009 but i need it to be multipart so that people that receives email from blackberry can also see it in plain/text. I know that when is html it works. 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.