?
Solved

<br> tags in phpmailer

Posted on 2009-04-26
5
Medium Priority
?
468 Views
Last Modified: 2013-12-13
Is it possible to make <br> in text which is went throug phpmailer. Text comes in normal form textarea and there need to be <br> there where user have press enter? I dont figure it out and help would be greatly appreciated.
<?php 
 $query=mysql_query('SELECT `email`,`name` FROM `mailikokeilu`'); //grab emails and names from database
while($row = mysql_fetch_array($query)) 
{
$aika = date("d/m/Y");
$message = "{$_POST['viesti']}<br /><br />";  <<< <BR> TAGS IN HERE
$subject = "Ky";
include_once('phpmailer/class.phpmailer.php'); 
$mail = new PHPMailer();
$body = eregi_replace("[\]",'',$body);
$mail->From = "no-reply@test.fi";
$mail->FromName = "Ky";
$mail->IsHTML(True); 
$mail->Subject  =  $subject; 
$mail->Body =  $message;  <<< <BR> TAGS IN HERE
$mail->Body = "
 
<table width=\"500\" border=\"0\" align=\"center\" cellpadding=\"4\" cellspacing=\"4\" bordercolor=\"#000000\" bgcolor=\"#CFECF8\">
<tr><td width=\"323\" align=\"left\" valign=\"top\">
  <p><font color=\"#000000\" size=\"2\" face=\"verdana\">Message</font></td>
  <td width=\"153\" align=\"right\" valign=\"middle\"><font face=\"verdana, arial\" size=\"1\" color=\"#000000\">$aika</font></td>
</tr>
<tr><td colspan=\"2\"><font face=\"verdana, arial\" size=\"2\" color=\"#000000\">$message</font></td></tr>
<tr><td colspan=\"1\"><font face=\"verdana, arial\" size=\"1\" color=\"#000000\">http://www.test.fi/</font></td>
</tr>
</table>
";
$mail->AddAttachment("ky_header.gif");             // attachment
$mail->IsHTML(True);    
    $mail->AddAddress($row['email'], $row['name']);
    if(!$mail->Send()) {
      echo '<p>Mailer Error: ' . $mail->ErrorInfo .'</p>';
    } else {
      echo '<p>Message sent to: '.$row['name'].' at their email address: '.$row['email'].'!</p>';
    }
}  
?>

Open in new window

0
Comment
Question by:tikkanen
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
mstrelan earned 500 total points
ID: 24237928
www.php.net/nl2br
this function converts line breaks to html br's
just run it around the posted textarea value
$message = nl2br($_POST['viesti']);
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 24238542
Change <br> to \n.

$message = "{$_POST['viesti']}\n\n";
0
 
LVL 10

Expert Comment

by:mstrelan
ID: 24238556
@cyberwebservice i don't think this is what tikkanen is asking... the question asks for the users textarea input enters to be converted to <br />'s ... therfore there needs to be a string replacement, not a string concatenation

nl2br will do the trick
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 24238606
@mstrelan, according to my understanding the asker wants line breaks in the php mail. Now the line breaks are shown as "<br>" in the email which should be converted to new line.
0
 

Author Closing Comment

by:tikkanen
ID: 31574753
Just like this, thank you very much!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question