Gossamer Forum
Home : General : Perl Programming :

New Line \n

Quote Reply
New Line \n
Hi,
I'm using the following sub to send an email and have a question about the new line "\n" in the message body.
The way it is written below gives me double line spacing. If I remove the "\n" I get single line spacing.
What I would like to know is - Do different mail applications interpret it in different ways?
For example, I'm using Thunderbird and it displays as I have mentioned above but will OE, Eudora, etc. layout the message in the same way?
Also, does everything between the <<MAIL_BODY; MAIL_BODY usually get displayed as it is layed out?
E.G without the "\n" every line is being displayed on a new line.
Could some explain how this works and the best method to use so all my users see the message layed out in the same way. (I don't want to use html in the message).
Thanks.
Simon.

sub {
require GT::Mail;
my $tags = GT::Template->tags;
# Create Message
my $msg= <<MAIL_BODY;
Line 1\n
Line 2\n
Line 3\n
Line 4\n
etc....
MAIL_BODY

my $to = "$tags->{email}";
my $from = "name\@domain.com";
my $sbj = "Subject";
# Send Message
GT::Mail->send (
'Content-type' => 'text/plain',
sendmail => $CFG->{db_mail_path},
to => $to,
from => $from,
subject => $sbj,
msg => $msg
) or die "Error: $GT::Mail::error";

#end of sub
}
Quote Reply
Re: [jai] New Line \n In reply to
Hi,

The reason is down to this part;

Code:
my $msg= <<MAIL_BODY;
Line 1\n
Line 2\n
Line 3\n
Line 4\n
etc....
MAIL_BODY

Basically, its being read as;

Code:
my $msg= <<MAIL_BODY;
Line 1\n\n
Line 2\n\n
Line 3\n\n
Line 4\n\n
MAIL_BODY

Note your \n, and also the literal one (i.e where you've pressed "Return").

In theory you should only need;

Code:
my $msg= qq{
Line 1
Line 2
Line 3
Line 4
};

..or maybe better (depending on any variables you want to include here);

Code:
my $msg= qq|
Line 1
Line 2
Line 3
Line 4
|;


Hope that helps Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] New Line \n In reply to
Thanks Andy.

Quote:
Note your \n, and also the literal one (i.e where you've pressed "Return").

OK, so it does read the literal one, that's what I was wondering.



Code:
my $msg= qq{
Line 1
Line 2
Line 3
Line 4
};

..or maybe better (depending on any variables you want to include here);

Code:
my $msg= qq|
Line 1
Line 2
Line 3
Line 4
|;
What's the difference? Does one allow for variables and the other doesn't?


Also, how about the mail application side of things, do they all read the code the same way?

Thanks.
Simon.
Quote Reply
Re: [jai] New Line \n In reply to
Hi,

Quote:
OK, so it does read the literal one, that's what I was wondering.

Yup :)

Quote:
What's the difference? Does one allow for variables and the other doesn't?

They are just different ways of quoting the variables, without using the <<<HANDLE option.

All of these are valid;

Code:
qq{};
q{};
qq||;
q||;
q~~;
qq~~;

..etc.

The one's with single letters (i.e q{} and q||) are processed literally (i.e any variables inside it, don't get processed.. so if you have $test in there, it'll show up as $test, and not the value).

Hope that helps :)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] New Line \n In reply to
Thanks again !!!! Smile

No comment on the mail application side of things ???????? Frown
Quote Reply
Re: [jai] New Line \n In reply to
Hi,

No problem Smile

Quote:
No comment on the mail application side of things ???????? Frown

In terms of newlines? It should work in the same way... i.e if you use;

Code:
print MAILHEADERS qq|To: xxx <ggg@ggG>
From: xxx
Subject: Just aq test

Now you put your message here
|;

Hope thats what your asking =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] New Line \n In reply to
Hi Andy,
Is there any way to display links within the mail message body we have been talking about above?
I have explained what I want to do in the code below.


Code:
my $msg= qq{
If I include the url - http://www.domain.com my mail program displays it as a link.
But what I would like to do is display - "Click Here" rather than the actual url
Is there any way to do it if I'm using - 'Content-type' => 'text/plain' in my header???
Thank you.
};

Quote Reply
Re: [jai] New Line \n In reply to
i think u will need to switch text/plain to text/html to show clickable links but im not sure if with text/plain there is a way too.
Quote Reply
Re: [jai] New Line \n In reply to
Hi,

In that case, you may want to try;

Code:
GT::Mail->send (
'Content-type' => 'text/plain',
sendmail => $CFG->{db_mail_path},
to => $to,
from => $from,
subject => $sbj,
msg => $msg,
type => 'test/html'

) or die "Error: $GT::Mail::error";

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] New Line \n In reply to


Code:
GT::Mail->send (
'Content-type' => 'text/plain',
sendmail => $CFG->{db_mail_path},
to => $to,
from => $from,
subject => $sbj,
msg => $msg,
type => 'test/html'

) or die "Error: $GT::Mail::error";

Should that be -

type => 'text/html' ????
For this to work, do I just include the html in the message body?
<a href="http://www.domain.com>Click Here</a>

And will it display if the user has their mail application set for TEXT messages only?

What's the difference between doing it the way you have suggested or changing the
'Content-type' => 'text/plain', to 'Content-type' => 'text/html', ??


Thanks for your help.
Simon.
Quote Reply
Re: [jai] New Line \n In reply to
Hi,

Yeah, sorry.. touch typing for you <G> It should have been "text", and not "test".

Quote:
And will it display if the user has their mail application set for TEXT messages only?

Not really. But to be honest, I don't know anyone who uses just plain text parsers now. Even web-based email accounts let you view HTML (some more than others).

Quote:
What's the difference between doing it the way you have suggested or changing the 'Content-type' => 'text/plain', to 'Content-type' => 'text/html', ??

test/plain wouldn't process it as a link (unless their email client did it for them).

The text/html content type means that you can do all kinds of things, i.e;

<center><b>testing</b></center>

..which you obviously can't do in plain format (as it would be processed literally).

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!