Jump to content

sending html in an email script


Dragen

Recommended Posts

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

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.