brentman Posted July 6, 2015 Share Posted July 6, 2015 I am trying to send a basic email that is multipart via the mail() function in php. I am not interested in using PHPmail. This should be very light weight. Currently when I send email to gmail, it is sending the html part as plain text so all the tags are showing. Here is my code: //GET VAR INPUT $to = htmlentities($_GET['to']); $friendly_from = htmlentities($_GET['friendly_from']); $email_from = htmlentities($_GET['email_from']); $subject = htmlentities($_GET['subject']); $text = htmlentities($_GET['text']); $html = htmlentities($_GET['html']); //SEND EMAIL # Setup mime boundary $mime_boundary = 'Multipart_Boundary_x' . md5(time()) . 'x'; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n"; $headers .= "Content-Transfer-Encoding: 7bit\r\n"; $headers .= "Reply-To: " . $email_from . " \r\n"; # Add in plain text version $body.= "--$mime_boundary\n"; $body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n"; $body.= "Content-Transfer-Encoding: 7bit\n\n"; $body.= $text; $body.= "\n\n"; # Add in HTML version $body.= "--$mime_boundary\n"; $body.= "Content-Type: text/html; charset=\"UTF-8\"\n"; $body.= "Content-Transfer-Encoding: 7bit\n\n"; $body.= $html; $body.= "\n\n"; # End email $body.= "--$mime_boundary--\n"; # <-- Notice trailing --, required to close email body for mime's # Finish off headers $headers .= "From: " . $friendly_from . " <" . $email_from . ">\r\n"; $headers .= "X-Sender-IP: " . $_SERVER[SERVER_ADDR] . "\r\n"; $headers .= 'Date: ' . date('n/d/Y g:i A') . "\r\n"; # Mail it out return mail($to, $subject, $body, $headers); Here is what I am receiving. (And yes I can accept html emails). Link to comment https://forums.phpfreaks.com/topic/297193-multipart-mail-not-sending-correctly/ Share on other sites More sharing options...
brentman Posted July 6, 2015 Author Share Posted July 6, 2015 Solved: wow htmlentities() caused the problem. That was stupid. Nobody say anything. Link to comment https://forums.phpfreaks.com/topic/297193-multipart-mail-not-sending-correctly/#findComment-1515661 Share on other sites More sharing options...
brentman Posted July 6, 2015 Author Share Posted July 6, 2015 Anyone feel free to use the code I have for mailing, it appears to work well. Link to comment https://forums.phpfreaks.com/topic/297193-multipart-mail-not-sending-correctly/#findComment-1515662 Share on other sites More sharing options...
mac_gyver Posted July 6, 2015 Share Posted July 6, 2015 htmlentities() would be used on the CONTENT being put into the html markup, that you want to be rendered literally as typed, and also making any javascript/css/html markup in the content, inert. if your $_GET['html']/$html IS the html markup for the page, no, you would not pass it through htmlentities(). i'm hoping that you have some security in place to prevent just anyone from submitting whatever they want to your code? Link to comment https://forums.phpfreaks.com/topic/297193-multipart-mail-not-sending-correctly/#findComment-1515663 Share on other sites More sharing options...
brentman Posted July 6, 2015 Author Share Posted July 6, 2015 Yes I do. I am using htmlentities on the variables right before this and it is password protected pages that are only for me. Link to comment https://forums.phpfreaks.com/topic/297193-multipart-mail-not-sending-correctly/#findComment-1515671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.