I’ve created a very simple PHP system to send emails to a mailinglist using a MySQL database and PHP. It’s not finished yet and as mails sent through the mail() function go into the junk-folder in most mailing programs straight away, I’ll connect to my SMTP server using PHP in the future. Though there’s something that I’d like to solve first.
<table border="0">
<form method="post" action="send.php">
<tr><td>Onderwerp:</td><td><input type="text" style="width:200px;" name="sub" /></td></tr>
<tr><td>Bericht:</td><td><textarea name="mes" style="width:200px; height:100px;"></textarea></td></tr>
<tr><td></td><td><input type="submit" style="width:200px;" value="Verzend" /></td></tr>
</form>
</table>
When a message is filled in in the above textarea it is submitted to the following script (send.php):
while($row = mysql_fetch_array($result)){
$to = $row['email'];
$subject = $_POST['sub'];
$message = $_POST['mes'];
$headers = 'From: from@from.com>' . "\r\n" . 'Reply-To: reply@reply.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
}
Of course there’s some more script above this to connect to the db etc., but that’s not relevant here. As you can see, the message text received through $_POST is put into a variable used in the mail() function.
But when I use multiple lines in the textarea, at some point in the script this is all converted into one huge line which will create a messy email in the end. As some of you might have seen, I’ve already created a header that says the mail’s content is HTML. This is because I put a <p> element around the text sent through $_POST. I tried to remove this as it might be the thing converting it all into one line. But this didn’t help.
Of course you can use <br /> in HTML, but it would be silly to ask all the users of the list to use that to create a new line. So: Is there a way to make the multiple lines remain in the email without having to fill in anything different in the textfield?
Thanks for answering in advance!
Perhaps ypu are looking for nl2br function in php..