Forum Moderators: coopster & phranque

Message Too Old, No Replies

formmail.cgi - message format

is it possible to insert space between paragraphs in a message?

         

stavs

1:25 pm on Jul 20, 2002 (gmt 0)

10+ Year Member



I want to use formail.cgi (the web form to email script) to allow us to send standard emails to clients. I would like to be able to simply drop an email address into a form field, press submit and have a pre-defined message sent to that address.

So far so good...BUT, I can't find a way of inserting spaces in the body of the message to separate the paragraphs and also the signature at the bottom of the text.

I am using this code for the message body:

<input type=HIDDEN name="Message" value="This is the message which is about 20 lines long">

Is there some way I can break up the sentences so it doesn't come out as just one long continuous paragraph. I can't imagine that the creators of formmail would not have thought of this but I cannot find any reference to it anywhere.

Any ideas, colleagues?

bobriggs

2:58 pm on Jul 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not formmail, its any browser.

You'd need some way to url-encode the line breaks, but I think if you used %, then the browser would url-encode that, not the result you want.

Including line breaks between the quotes in your hidden 'value' probably won't work either, the browser probably will just convert them to space characters, as it should.

If you do formmail and add line breaks in the body of the message (that you can type in, as opposed to a hidden field), the browser sees that you've pressed 'enter' or 'return' and sends those url-encoded. Formmail unencodes these and sends the message correctly.

There might be a way to get a browser to do it, but I can't think of any.

[added]
Well, you can. If you'll use some character sequence that is not really going to be in any other message, then modify formmail to do a replace on that sequence of characters, this will work.

$Form{'message') =~ s/yourspecialsequence/\n/;

bobriggs

4:38 pm on Jul 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As usual I always think of a harder way to do things.

Wherever you want a new line, insert this:

&#13;&#10;

I tried it and it works. You might even be able to get away with just &#10; - I'm not sure if it's platform dependent or not.

Key_Master

9:38 pm on Jul 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I threw it together but the following code will format $FORM{'message'} with a maximum of 15 words per line.

@parse_body = split(/ /, $FORM{'message'});
foreach $_ (@parse_body) {
$x++;
$body .= "".$_." ";
if ($x == 15) {
$body .= "\n";
$x = 0;
}
elsif ($_ =~ /\n/) {
$x = 0;
}
}

print MAIL $body; # Variable to write to E-mail

stavs

10:44 am on Jul 21, 2002 (gmt 0)

10+ Year Member



Thanks very much, fellas for your time on this.

Unfortunately I can't get anything to work. Tried using the &#13;&#10; code in the message body but it won't break the line. Could it be a Internet Explorer 6 problem?

Nightmare.

stavs

11:13 am on Jul 21, 2002 (gmt 0)

10+ Year Member



And, any idea how to get rid of this line:

'SUBMIT: Send e-mail'

which always appears on the bottom of the email.

Thanks Again!

bobriggs

11:16 am on Jul 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well I tried &#13;&#10; in both opera and IE6. No problem here when I receive the email.

Are you just looking at the confirmation line (the output that formmail gives you that shows what you sent? That will NOT display as a new line because it is html. (it would if you used <pre> which is probably what formmail should output).

stavs

11:24 am on Jul 21, 2002 (gmt 0)

10+ Year Member



Thanks for getting back to me Bobriggs.

I added the code like this:

<input type=HIDDEN name="Message" value="This is the message which is about 20 lines long &#13;&#10; so its good to break up the message into paragraphs">

But it just won't break the line - is this the correct syntax?

bobriggs

11:24 am on Jul 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're seeing SUBMIT: Send email

Then remove the name="SUBMIT" from your

<input type="submit" name="SUBMIT" value="Send e-mail"> line.

bobriggs

11:26 am on Jul 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Make sure you're reading it in your email client. It should be broken into two lines there. Don't assume the output on the screen after you submit is what it will look like in the actual email.

That's the correct syntax. You don't really want the space after the &#10; but the line should be broken in two.

stavs

11:28 am on Jul 21, 2002 (gmt 0)

10+ Year Member



Okay, got rid of the submit line - thanks for that Bobriggs.

stavs

11:32 am on Jul 21, 2002 (gmt 0)

10+ Year Member



I am reading the email from Outlook - and there is no line break.

Which version of Formmail are you using, Bobriggs? do you think different versions would work differently in respect to the linebreaks. I am using 1.92.

bobriggs

11:38 am on Jul 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, my copy says 1.6. But I've done my own editing of it since then (all the security stuff - post only, email address only to me, other customization)

Give me a link to the new one (or your version) and I'll be glad to take a look at it to see what's happening to these fields. (Could be a filter added to all input lines to strip newlines)

stavs

12:02 pm on Jul 21, 2002 (gmt 0)

10+ Year Member



Bobriggs - I really appreciate your help on this - thanks for sticking with me.

I got the script here:

[scriptarchive.com...]

bobriggs

12:05 pm on Jul 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just downloaded a copy of 1.92, changed the required lines and sent myself an email. The lines broke perfectly.

I used:
<input type="hidden" name="message" value="This is a test&#13;&#10;Another line">

and the corresponding portion of the email returned:

message: This is a test
Another line

--
You can see that message broke into two lines. Using IE6 on win2k, outlook express.

bobriggs

12:15 pm on Jul 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you've already double checked your code, made sure ampersands and semicolons were correct, then I'd add another field like this into your form:

<textarea name="testtextarea" rows="8" cols="40" >First line&#13;&#10;&#13;&#10;Second line</textarea>

This will make sure that your browser is reading the newline codes correctly. Are the lines separated by a blank line when you load the form?

Also, I don't think it should make a difference, but are you using GET or POST?

stavs

12:23 pm on Jul 21, 2002 (gmt 0)

10+ Year Member



Bobriggs - I found the problem - OUTLOOOK 2000 - no line breaks. I just tried using Outlook Express and it works fine.

That is seriously annoying ;-)

What on earth could be causing the problem with Outlook 2K ? Do you think there is a way around it.

Thanks again!

bobriggs

12:36 pm on Jul 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first thing I can think of with outlook is maybe it's trying to display html - that CR/LF pair will not show up in html.

Take a look at the result in OE, (properties, details tab). Any headers in there that might cause outlook to display the email as html?

stavs

1:00 pm on Jul 21, 2002 (gmt 0)

10+ Year Member



Hi

No, I'm not seeing anything to indicate that. All indications are that the email is in plain text on both O2k and OE. Wonder why O2k isn't interpreting the message in the same way - very odd.

bobriggs

1:10 pm on Jul 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can dup your problem. (I loaded Outlook 2000 and I see what you're seeing).

I'll be looking for something that will tell me how to correct this - Since I use the sendmail for plain text on my servers for many other functions, and I depend on those line breaks.

stavs

1:13 pm on Jul 21, 2002 (gmt 0)

10+ Year Member



Thanks Bobriggs - I have every confidence in you.

I don't know how you guys make sense of perl - must be great to be able to modify scripts by yourself.

bobriggs

2:13 pm on Jul 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Solution found.

There are 2 problems.

I changed &#13;&#10; to just &#10; and got the same problem. Then before the mail had been sent I checked the raw data in the mailbox. Both IE AND Opera convert just the &#10; back to &#13;&#10; (carriage return/line feed)

Outlook does not like the carriage return (&#13;) it only expects the line feed (newline)

So add this line to formmail.pl

$value =~ s/\r//g;

right after these three lines:

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/\0//d;

That strips ANY carriage returns from any values sent (which shouldn't be there anyway)

stavs

11:27 am on Jul 22, 2002 (gmt 0)

10+ Year Member



Bobriggs - THANKS!

Works great - I really appreciate your help.

Best Wishes,

Stavs

stavs

11:40 am on Jul 22, 2002 (gmt 0)

10+ Year Member



Damn, I can't believe this - all the time, I have been testing this, I was using a recipient with an email address from the same domain as the website - I just tried an alternative address and it's a 'bad recipient'. There is a recipient configurable in the script so that you can define which email addresses can be a recipient:

@recipients = &fill_recipients(@referers);

But I want to use any email address as I am sending messages to clients, not myself. Do you know of a way to define this?

Thanks again, Bobriggs - hopefully, this will be the end of my problems ;-)

Stavs

bobriggs

12:58 pm on Jul 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sent you a sticky mail.