occorled Posted March 30, 2008 Share Posted March 30, 2008 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? Quote Link to comment Share on other sites More sharing options...
occorled Posted March 30, 2008 Author Share Posted March 30, 2008 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" ); } ?> Quote Link to comment Share on other sites More sharing options...
occorled Posted April 1, 2008 Author Share Posted April 1, 2008 *bump* :'( Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 1, 2008 Share Posted April 1, 2008 Just tested that code on my server and the email was sent without HTML tags. Have you tried echo'ing $message rather than sending the mail? Perhaps something in your script is modifying the variable. Quote Link to comment Share on other sites More sharing options...
occorled Posted April 1, 2008 Author Share Posted April 1, 2008 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? Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 1, 2008 Share Posted April 1, 2008 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 Quote Link to comment Share on other sites More sharing options...
occorled Posted April 2, 2008 Author Share Posted April 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 2, 2008 Share Posted April 2, 2008 It appeared fine on my end, in case you didn't get my response. GMail is probably doing nl2br or similar in order to display on their webpage properly Quote Link to comment Share on other sites More sharing options...
occorled Posted April 2, 2008 Author Share Posted April 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
occorled Posted April 2, 2008 Author Share Posted April 2, 2008 oh.... i just checked your mail lolz looks like it is right on yours... I don't get it. It doesn't work when I send it to GMail account or a Microsoft Outlook account?? What are you using to check your mail? Quote Link to comment Share on other sites More sharing options...
occorled Posted April 2, 2008 Author Share Posted April 2, 2008 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... 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.