Skip to main content
Inspiring
February 22, 2008
Question

Line breaks deleted when Flash variables sent to PHP

  • February 22, 2008
  • 1 reply
  • 339 views
Hi all -

I have a designed a Flash based interface to send email via PHP.

I capture the variables in Flash using:

var my_lv:LoadVars=new LoadVars();
my_lv.name=name_txt.text;
my_lv.message=message_txt.text;
// ...
// ...
my_lv.send("mail.php","POST");

My PHP reads:

<?php

$headers = "From: " . $_POST["name"];
$headers .= "<" . $_POST["from"] . ">\r\n";
$headers .= "Reply-To: " . $_POST["from"] . "\r\n";
$headers .= "Return-Path: " . $_POST["from"];

$to = $_POST['to'];
$message=stripslashes($_POST['message']);
//NOTE: I tried $message without stripslashes - same results
$subject=stripslashes($_POST['subject']);
mail($to, $subject, $message, $headers);

?>

When the message is received all line breaks using RETURN/ENTER in Flash message .swf are deleted making the message one long line when viewed by the recipient. Is there something I need to write into my actionscript/php to allow the message to recognize these hard line breaks and display properly in the recipient's email client? I'm guessing (hoping!) it's an easy fix. BTW, the messages do display properly in 'some' clients and not others. I need some fix that will correct this across the board.

Thanks in advance -
This topic has been closed for replies.

1 reply

Inspiring
February 23, 2008
hmmm.. I'm using Apple mail client and it's working fine.
Inspiring
February 23, 2008
Hi chop*

Yeah, that's what I was saying in my original post -- it does work in some clients. I notice that it doesn't work when accessing the email via the www using my personal @sbcglobal.net acct. The email comes over as one long woooooorrrrddddd w/o breaks or spaces inserted during composition. Before I deploy this script on someone's site, I want to make sure that it works infallibly and across all browsers and platforms. I work as a freelance designer and don't want to sell my clients a feature that just works 'most of the time'. It's gotta' be bulletproof.
February 25, 2008
Hello,

try with this piece of code in your php file

$message = $_POST['message'];
$message = preg_replace("/\r/","<BR>",$message);

this will replace the \r sent by flash to BR witch will be correctly read by any email client