Contact form excludes line breaks in message body

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Contact form excludes line breaks in message body

Post by Leao »

Hi,

I've got a contact form on my Flash website that sends its variables to the attached PHP script and consequently sends an email onto me. It all works perfectly except the email I receive always misses out the line breaks contained within the $yourmessage variable. For example if someone writes their address to me like this:
Joe Bloggs
10 Lime Avenue
London
UK


The email will present their address to me with the line breaks removed like this:
Joe Bloggs10Lime AvenueLondonUK

How can I resolve this issue?

Many thanks,

Leao

Code: Select all

<?
$to = 'mail@mydomain.org';

$subject = 'St. Patrick\'s message';

$body = "You have received a message via the St. Patrick's website. The details of the message are listed below...\n\nName: $yourname\nEmail: $youremail\nMessage: $yourmessage";

$body = wordwrap($body, 70);

$headers = "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: mail@mydomain.org\r\n";
$headers .= "Return-Path:mail@mydomain.org\r\n";
$headers .= "Reply-To: $youremail\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion()."\r\n";

mail($to, $subject, $body, $headers, "-fmail@mydomain.org.org");
?>
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Is $yourmessage entered in some flash textbox or in <textarea> element ?
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Post by Leao »

miro_igov wrote:Is $yourmessage entered in some flash textbox or in <textarea> element ?
It's entered in a Flash input text box,

Leo
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Then try to determine what is the ascii code of the line separator for this box and replace this character with line feed '\n'

To do it you can use

Code: Select all

$strlength = strlen($yourmessage);
   $retString = "";
   for($i = 0; $i < $strlength; $i++){
       
           $retString .= $yourmessage[$i];
      
   }
  
   echo $retString;
and enter in this text box only few <enter>

Once you determine what is the ascii number for this char you can use

Code: Select all

$yourmessage = str_replace(chr($ASCIINo),'\n',$yourmessage)
where $ASCIINo will be the number you just received when echoing $retStr
Leao
Forum Commoner
Posts: 49
Joined: Mon Aug 21, 2006 8:57 pm
Location: London

Post by Leao »

Hi,

It's difficult to view the echoed results as when Flash connects to a PHP script it does so without the user being able to view the process. Is there an alternative way of doing this?

Many, many thanks,

Leo
Post Reply