Page 1 of 1

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

Posted: Fri Apr 24, 2009 4:33 pm
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

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

Posted: Fri Apr 24, 2009 4:46 pm
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);

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

Posted: Fri Apr 24, 2009 4:50 pm
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
 
";
 
 

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

Posted: Fri Apr 24, 2009 6:25 pm
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