<br> tags in phpmailer

Posted on 2009-04-26
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.

 $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";


$mail = new PHPMailer();

$body = eregi_replace("[\]",'',$body);

$mail->From = "";

$mail->FromName = "Ky";


$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><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\"></font></td>




$mail->AddAttachment("ky_header.gif");             // attachment


    $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

Question by:tikkanen
    LVL 10

    Accepted Solution

    this function converts line breaks to html br's
    just run it around the posted textarea value
    $message = nl2br($_POST['viesti']);
    LVL 16

    Expert Comment

    by:Haripriya Sathiish
    Change <br> to \n.

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

    Expert Comment

    @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
    LVL 16

    Expert Comment

    by:Haripriya Sathiish
    @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.

    Author Closing Comment

    Just like this, thank you very much!

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now