Jump to content

Display problem using mail()


elmas156

Recommended Posts

I have a messaging system that I'm trying to send a notification by email to a specific person when a new message is entered.  Everything is working fine except how the message is displayed in the email.  Here's the problem:

 

When the message reads:

 

"This is a test.

 

This should be two lines down.

This is on the next line!"

 

this is what is displayed in the email:

 

"This is a test.\r\n\r\nThis should be two lines down.\r\nThis is on the next line!"

 

How I'm displaying the message is by inserting it into a database first.  Then I do a query to pull it back from the database on another page using the variable $message.  I have tried using just $message and using nl2br("$message") and they both display as shown above.  Does anyone have any ideas on how to get the message to display properly in the email?

 

Here's the code that I'm using to send it in if it will help:

<?php
$message2 = nl2br("$message");
$sendto2 = "$email";
$emailsubject2 = "New Message";		
$emailmessage2 = "<html>
<body>
<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td>
$prefix $lname,
<p>
This message is to notify you that a new message has been sent.  A copy of the message has been included below.<br>
<hr width=\"500\"><br>
<strong>Subject: \"$subject\"</strong>
<p>$message2</p>
Thank you!
</td>
</tr>
</table>
</body>
</html>";

// To send HTML mail, the Content-type header must be set
$headers2  = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers

$headers2 .= 'From: Admin <[email protected]>' . "\r\n";

// Mail it
mail($sendto2, $emailsubject2, $emailmessage2, $headers2);
?>

Link to comment
https://forums.phpfreaks.com/topic/219232-display-problem-using-mail/
Share on other sites

I would try closing the HTML, concatenate, PHP, concatentate, HTML

 

Example

 

<td>" . "$vars" . "</td>"

 

Also, Check your HTML - your line breaks are not closed <br />

 

In addition - I would try some CSS in there for instance

 

<style>

p {

margin: 0, 0, 0, 0;

padding: 0, 0, 0, 0;

}

 

.bodytext{

margin-top: 20px;

}

</style>

 

<p class="bodytext">Message Here</p>

 

Let me know.

It's not the HTML that isn't displaying properly, that part looks fine.  The problem comes where the actual message is displayed.  Basically, it's displaying "/r/n" everywhere there is a line break in the message.  Again, the rest of the message displays fine, it's only the line breaks in the message that I'm pulling from the database that I'm having problems displaying properly.  Thanks for your suggestion though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.