-1

I am having trouble trying to display my html code properly (without the html tags) when it gets sent out through email via a php file. What $header or $nmessage am I missing for it to display properly when a recipient receives the email?

My php script is shown below with the html code left out:

<?php

if(@$_REQUEST['weakPassword'] != "TEST")
{
echo "failed";
die();
}

function mail_attachment_from_file($the_file, $filename , $mailto, $from_mail, $from_name, $replyto, $subject, $message) 
{
$content = $the_file;
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$nmessage = "--".$uid."\r\n";
$nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$nmessage .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$nmessage .= $message."\r\n\r\n";
$nmessage .= "--".$uid."\r\n";
$nmessage .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
$nmessage .= "Content-Transfer-Encoding: base64\r\n";
$nmessage .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$nmessage .= $content."\r\n\r\n";
$nmessage .= "--".$uid."--";

mail($mailto, $subject, $nmessage, $header);

return true;
}

$to = @$_REQUEST['emailGuest'];
$from = @$_REQUEST['emailFrom'];

$subject = @$_REQUEST['emailSubject'];

$message = '
<html>
// HTML code
</html>';

$fileName = @$_REQUEST['fileName'];

$sep = sha1(date('r', time()));

// Read in our file attachment
$the_file = file_get_contents($_FILES['Filedata']['tmp_name']);

mail_attachment_from_file($the_file, $fileName , $to, $from, "BLAH", $from, $subject, $message);

echo "done";

?>
4
  • 1
    Content-type:text/plain; charset=iso-8859-1 this is your culprit. You are saying that the email is sent with plain text format Commented Dec 1, 2017 at 5:12
  • You may also want to consider using PEAR or other libraries that can assist in creating the proper MIME Boundaries for your mail. This will help ensure it looks less like SPAM and meets RFC Standards. Also remember that RFC states if you are sending HTML Formatted email, there should be a proper TEXT MIME version too. Commented Dec 1, 2017 at 5:17
  • @Twisty would you recommend PEAR or the phpmailer library? Commented Dec 1, 2017 at 5:19
  • I am a fan of PEAR personally. pear.php.net/packages.php?catpid=14&catname=Mail Try Mail2 and Mail_MIME2. Commented Dec 1, 2017 at 5:20

1 Answer 1

1

Change your Content-Type to this:

$nmessage .= "Content-type: text/html\r\n";

From this:

$nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n";

Check here:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.