Dragen Posted June 2, 2007 Share Posted June 2, 2007 I'm sure this has been asked many times before but I've got an email script which sends an email to both my client and myself. I know that if I put html in the email, such as <strong>hi</strong> It outputs: <strong>hi</strong> instead of: hi How do I set it to accept html? or is there another way of entering html? Is it to do with the content-type? I'm using: "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; using miltipart/mixed, because I'm sending attachements with the email. Thanks Quote Link to comment Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 $header.="Content-Type: text/html\n"; Quote Link to comment Share on other sites More sharing options...
Dragen Posted June 2, 2007 Author Share Posted June 2, 2007 But I thought if I'm sending attachements then the content-type needed to be multipart/mixed Quote Link to comment Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 ... not... exactly... you create a boundary... so it knows that part of the email is file, other part is text/html Quote Link to comment Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 besides... text is sent through the mail($text...) field... files are sent through headers ;-) Quote Link to comment Share on other sites More sharing options...
Dragen Posted June 2, 2007 Author Share Posted June 2, 2007 hmm.. I think I've coded it wrong in that case.. If I changs the type to text/html it just output a load of random letters and numbers instead of the attachement: PHVsPg0KCQkJPGxpPjxzdHJvbmc+V2hvIG93bnMgdGhlIHdlYnNpdGU/PC9zdHJvbmc+DQoJCQkJ PHVsPg0KCQkJCQk8bGk+WW91ICh0aGUgY2xpZW50KSBhcmUgaGlyaW5nIEdpbXAgUHJvZHVjdGlv bnMgdG8gcHJvZHVjZSBhIHdlYnNpdGUgZm9yIHlvdXIgbmVlZHMgYW5kIHNwZWNpZmljYXRpb25z LjwvbGk+DQoJCQkJCTxsaT5UaGUgY2xpZW50IGlzIGJ1eWluZyB0aGUgZmluYWwgb3V0Y29tZSBv ZiB0aGUgd2Vic2l0ZSBhcyBhIGZpbmlzaGVkIHByb2R1Y3QgYW5kIHRoZXJlZm9yZSB0aGUgY2xp there's a lot more but I thought I'd let you off reading it all here's the code I'm using: if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])>7 || !strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])) die("Bad referer"); // get the sender's name and email address // we'll just plug them a variable to be used later $from = stripslashes($_POST['sig']) . "<dragen@gimppro.co.uk>"; // generate a random string to be used as the boundary marker $mime_boundary = "==Multipart_Boundary_x" . md5(mt_rand()) . "x"; // now we'll build the message headers $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html;\r\n" . " boundary=\"{$mime_boundary}\""; $message = "<strong>client acknowledgement form</strong>:\n"; $message .= "The undersigned persons have read and accepted the terms displayed in the attached client acknowledgement form.\n"; $message .= "<strong>" . $_POST['sig'] . "</strong>\n\n"; $message .= "Yours Sincerely,\n"; $message .= "Lee Croucher\n"; $message .= "gimp productions"; // next, we'll build the invisible portion of the message body // note that we insert two dashes in front of the MIME boundary // when we use it $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"; // now we'll process our acknowledgement file $file = "toa.txt"; // opens the txt file for the item. Then sets description as the text file. $fh = fopen($file, 'rb'); if(!$fh){ echo "Can't find acknowledgement file: " . $file; exit; }else{ // read the file content into a variable $data = fread($fh, filesize($file)); // close the file fclose($fh); // now we encode it and split it into acceptable length lines $data = chunk_split(base64_encode($data)); // now we'll insert a boundary to indicate we're starting the attachment // we have to specify the content type, file name, and disposition as // an attachment, then add the file content. // NOTE: we don't set another boundary to indicate that the end of the // file has been reached here. we only want one boundary between each file // we'll add the final one after the loop finishes. $message .= "--{$mime_boundary}\n" . "Content-Type: text/html;\n" . " name=\"clientform\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$file}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; } // here's our closing mime boundary that indicates the last of the message $message .= "--{$mime_boundary}--\n"; $recipient = "dragen@gimppro.co.uk"; $subject = "Gimp client acknowledgement"; echo "\t<tr>\n\t\t<td>"; if (@mail($recipient, $subject, $message, $headers)){ echo '<p align="center" style="font-size:larger;">Thank you</p>'; echo '<p align="center">your signature has been sent to Gimp Productions for verification and we will get back to you as soon as possible.</p>'; }else{ echo "<p align='center'><span class='header'>An error occurred and the message could not be sent.</span><br /><a href='javascript:history.go(-1);'>please try again</a></p>"; } echo "<td>\n\t<tr>\n"; 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.