How to make \n\n into line break through mail() ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

How to make \n\n into line break through mail() ?

Post by lauthiamkok »

How to make \n\n into line break through mail() ?

This is my code so far...

Code: Select all

$to_email = 'name@yahoo.co.uk';
        
        $from_name = $row_info_sender['mai_name'];
        
        $host_email = "info@site.com";
        
        $subject = "My Blog: You have a comment!";
        
        $header = "from: http://www.site.com/blog/ <$host_email>";
        
        $message = "$from_name has just sent a comment on your post with the title of '$post_title'.\r\n\n";
        $message.= "'$cmt_content'\r\n\n";
        $message.= "thank you,\r\n";
        $message.= "the server\r\n";
        
        $sentmail = mail($to_email,$subject,$message,$header);
result:

XXX has just sent a comment on your post with the title of 'Project 1'.

'Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\n\nLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.'

thank you,
the server

but what I wish to receive in my email is this below actually,

'Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.'

Many thanks,
Lau
xplore
Forum Newbie
Posts: 16
Joined: Mon Apr 06, 2009 12:06 pm

Re: How to make \n\n into line break through mail() ?

Post by xplore »

lauthiamkok wrote:How to make \n\n into line break through mail() ?

This is my code so far...

Code: Select all

$to_email = 'name@yahoo.co.uk';
        
        $from_name = $row_info_sender['mai_name'];
        
        $host_email = "info@site.com";
        
        $subject = "My Blog: You have a comment!";
        
        $header = "from: http://www.site.com/blog/ <$host_email>";
        
        $message = "$from_name has just sent a comment on your post with the title of '$post_title'.\r\n\n";
        $message.= "'$cmt_content'\r\n\n";
        $message.= "thank you,\r\n";
        $message.= "the server\r\n";
        
        $sentmail = mail($to_email,$subject,$message,$header);
result:

XXX has just sent a comment on your post with the title of 'Project 1'.

'Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\n\nLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.'

thank you,
the server

but what I wish to receive in my email is this below actually,

'Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.'

Many thanks,
Lau

Might I suggest not a solution but a possible fix or different route to take using the wordwrap() function. Specify both parameters A) 'var *STRING' , B) 'var *INT' (this being the number of characters until the next line is created.

example :

$message = "this is text. text text text";
$message = wordwrap($message, 10);
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: How to make \n\n into line break through mail() ?

Post by deejay »

mail should work if you put the spaces in the call up code itself, ie

Code: Select all

 
 
# $message = "$from_name has just sent a comment on your post with the title of  $post_title
 
$cmt_content'
 
 
 
thank you
 
";
 
 
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Re: How to make \n\n into line break through mail() ?

Post by lauthiamkok »

deejay wrote:mail should work if you put the spaces in the call up code itself, ie

Code: Select all

 
 
# $message = "$from_name has just sent a comment on your post with the title of  $post_title
 
$cmt_content'
 
 
 
thank you
 
";
 
 
 
spence_noodle;4234080 wrote:Try this instead:

Code: Select all

 
$to_email = 'name@yahoo.co.uk';
        
        $from_name = $row_info_sender['mai_name'];
        
        $host_email = "info@site.com";
        
        $subject = "My Blog: You have a comment!";
        
        $header = "from: http://www.site.com/blog/ <$host_email>";
        
        $message .= $from_name. " has just sent a comment on your post with the title of " . $post_title . "
 
        " . $cmt_content . "
 
        thank you,
        the server";
        
        $sentmail = mail($to_email,$subject,$message,$header);
 
You only need to include '\r\n' in the headers and not inside the message area for the email.
hi thanks. i jst tried. but its still the same if the user inputs a line break in the form...


Code: Select all

xxx has just sent a comment on your post with the title of Project 1         Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.[COLOR="Red"]\n\n[/COLOR]Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.         thank you,        the server 
Post Reply