Jump to content

help - is mail() inserting html tags into my message?


occorled

Recommended Posts

I've got a simple email script that is attempting to email some form textarea message.  I've 'echo'ed the message out and it looks right (as plain text).  However, after I send it (using 'mail') I receive it with html tags inserted.  There is nothing special in the headers to enable html.  I *am* using postfix as mail server, and after googling I found a similar post.

 

My question for you guys is... is there something silly I'm doing in PHP/form or is this a postfix thing?

 

example, this plain text:

Hello,

This is a test to see if this textarea works properly.  Let me know if it does. Wiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.

CALL MEH!

Joe

 

is converted to:

Hello,<br>
<br>
<br>
<br>
This is a test to see if this textarea works properly.  Let me know if it does. Wiiiiiiiiiiiiiiiiiiiiiiiiiiiii<wbr>iiiiiiiiiii.<br>
<br>
<br>
<br>
CALL MEH!<br>
<br>

<br>
<br>
Joe<br>

 

WHAT THE FUDGE?

Link to comment
Share on other sites

Here is the script if interested.  The EOL is '\n' because my server is linux (debian-etch).

 

<?php
  # configuration - (specifics hidden for obvious reasons)
  $mailto    = "a valid string";
  $mailtoadr = "a valid email address";
  $subject   = "a valid string" ;
  $formurl   = "a valid url";
  $errorurl  = "a valid url";
  $thanksurl = "a valid url";

  # form input
  $name    = $_REQUEST['name'] ;
  $email   = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  # error checking
  if ( empty($name) || empty($email) || empty($message) ||
       ereg("[\r\n]", $name) || ereg("[\r\n]", $email) )
  {
    header( "Location: $errorurl" );
  }
  else
  {
    # header
    $eol = "\n";
    $headers = "From: ".$name."<".$email.">".$eol;
    $headers .= "X-Mailer: PHP v".phpversion().$eol;

    # test
    #echo($message);

    # sendmail
    mail( "$mailto <$mailtoadr>", $subject, $message, $headers );
    header( "Location: $thanksurl" );    
  }
?>

Link to comment
Share on other sites

Yes, I did that before I asked for help.

 

I've 'echo'ed the message out and it looks right (as plain text).

 

I'm starting to think this is something with postfix that I have configured incorrectly, maybe?

 

Anybody else ever see an issue like this?

Link to comment
Share on other sites

Try converting CRLF to LF or LF to CRLF respectively. This is a really strange problem.

 

Is there are chance that your email client or POP/IMAP server is doing this?

 

Try sending a test email to me {matt} [at] {doodoostyle.com} and I'll see if I'm getting the same issue

Link to comment
Share on other sites

Ok, I just sent it through the script to your account.

The only two email clients I have tested the message on are gmail accounts.

 

I'll try swapping $eol to CRLF, but I think I started with that (because I copied a script to start that must have been written for a Windows box) and the headers got corrupted.  My server is a Linux box so I'm pretty sure the headers should be set with LF only.

 

I don't think this would matter but I'm editing the script itself with Context on a Windows box, then uploading it a Linux box which is the server.  Also in Context I have it set to use UNIX (LF only).

 

THANKS so much for helping me out, I really appreciate it.

Link to comment
Share on other sites

Are you absolutely sure?

 

Are you sure that the spacing is the same as the original message?  Those inserted HTML breaks are not visible by default, I had to highlight select the message on the client side and use "View Selection Source" in Firefox to view the actual HTML used to display the message.

 

I'm only asking because I just checked the received message from Microsoft Outlook now and it is still messed up, so I don't think it is GMail.

 

original message:

Hello,

 

This is a test to see if this textarea works properly.  Let me know if it does. Wiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.

 

CALL MEH!

 

Joe

 

received message:

 

Hello,

 

 

 

This is a test to see if this textarea works properly.  Let me know if it does. Wiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.

 

 

 

CALL MEH!

 

 

 

Joe

 

 

Are you sure that "mail()" php function doesn't do something to the message by default unless other parameters are called or something before calling "mail" system command?  I just tried the "mail" system command from an ssh shell on my server and it sent the email correctly (to a gmail account)!  But when I go through this script... I get the converted version.

Link to comment
Share on other sites

Ok maybe this will help some others, I'm going to report what I've found out so far in case anyone runs into similar issues.

 

1. Sending message from ssh logged-in session on my server, via system command 'mail' sends proper plain-text email.

2. Sending message from PHP 'mail()' function (which supposedly maps to the same thing) is sending message with <br> tags inserted.

3. Some clients when they receive the email are smart enough to filter out these extra HTML <br> tags.

4. Some clients are not.

 

For instance:

- GMail will display the email as is.

- Microsoft Outlook will display the email as is.

- Mozilla Thunderbird will filter out the extra <br> tags.

- Whatever 'discomatt' is using will filter as well.

I've tested this by sending a plain-text email with extra inserted <br> tags on newlines and Thunderbird strips them as well.

 

I don't think this has anything to do with Postfix anymore since I can email from command line and plain-text emails are received on every client.  And I don't believe that certain clients are randomly inserting extra <br> tags into emails, especially GMail, and especially since I found that Thunderbird is indeed stripping unnecessary tags.

 

I do think this has something to do with the PHP v5.2.0-8+etch7 "mail()" function specifically.  Maybe I am not passing all the correct headers and not overcompensating to make sure that plain-text is sent.  Maybe I have a bug in my package version.  I have found that others have run into a similar issue, though I have still not found a reliable fix.

 

I am going to replace the "mail()" call in my script with a call to my system command "mail" and see what happens...

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.