Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

PHP Post removes spaces from strings

the mail() function

Moderators: macek, egami, gesf

PHP Post removes spaces from strings

Postby Bazz2002 » Mon Oct 17, 2011 11:58 pm

Hi I use a Flash to send order from a form to an email, however when the email arrives the strings holding the data has all extra spaces removed.

e.g. if the string contains:
1234 (5 spaces here) 1234 (5 spaces here) 1234

when the email arrives it looks like this:
1234 1234 1234

( I have had to put "(5 spaces here)" above in sample as this forum does the very same thing!!!)

Can any one advise why extra spaces in a string are removed?

the code I use is below
With thanks, Barry.

Code: Select all
<?php

$name     = $HTTP_POST_VARS['name'];
$order    = $HTTP_POST_VARS['order'];
$ref_no   = $HTTP_POST_VARS['ref_no'];
$phone    = $HTTP_POST_VARS['phone'];
$cell     = $HTTP_POST_VARS['cell'];
$email    = $HTTP_POST_VARS['email'];
$required = $HTTP_POST_VARS['required'];
$message  = $HTTP_POST_VARS['message'];

$item1   = $HTTP_POST_VARS['item1'];
$item2   = $HTTP_POST_VARS['item2'];
$item3   = $HTTP_POST_VARS['item3'];
$item4   = $HTTP_POST_VARS['item4'];
$item5   = $HTTP_POST_VARS['item5'];
$item6   = $HTTP_POST_VARS['item6'];
$item7   = $HTTP_POST_VARS['item7'];
$item8   = $HTTP_POST_VARS['item8'];
$item9   = $HTTP_POST_VARS['item9'];
$item10   = $HTTP_POST_VARS['item10'];
$item11   = $HTTP_POST_VARS['item11'];
$item12   = $HTTP_POST_VARS['item12'];
$item13   = $HTTP_POST_VARS['item13'];
$item14   = $HTTP_POST_VARS['item14'];
$item15   = $HTTP_POST_VARS['item15'];
$item16   = $HTTP_POST_VARS['item16'];
$item17   = $HTTP_POST_VARS['item17'];
$item18   = $HTTP_POST_VARS['item18'];
$item19   = $HTTP_POST_VARS['item19'];
$item20   = $HTTP_POST_VARS['item20'];
$total    = $HTTP_POST_VARS['total'];
$header    = $HTTP_POST_VARS['header'];
$trade    = $HTTP_POST_VARS['trade'];


// Remove Slashes Inserted by PHP

$name     = stripslashes($name);
$order    = stripslashes($order);
$ref_no   = stripslashes($ref_no);
$phone    = stripslashes($phone);
$cell     = stripslashes($cell);
$email    = stripslashes($email);
$required = stripslashes($required);
$message  = stripslashes($message);

$item1   = stripslashes($item1);
$item2   = stripslashes($item2);
$item3   = stripslashes($item3);
$item4   = stripslashes($item4);
$item5   = stripslashes($item5);
$item6   = stripslashes($item6);
$item7   = stripslashes($item7);
$item8   = stripslashes($item8);
$item9   = stripslashes($item9);
$item10  = stripslashes($item10);
$item11  = stripslashes($item11);
$item12  = stripslashes($item12);
$item13  = stripslashes($item13);
$item14  = stripslashes($item14);
$item15  = stripslashes($item15);
$item16  = stripslashes($item16);
$item17  = stripslashes($item17);
$item18  = stripslashes($item18);
$item19  = stripslashes($item19);
$item20  = stripslashes($item20);
$total   = stripslashes($total);
$header   = stripslashes($header);
$trade   = stripslashes($trade);

// $phone = stripslashes($phone); // example of an additional input field

$headers = "From: $name <$email>";//put you own stuff here or use a variable
$to = "sales@xxxxxxxxx.co.nz, $email" ;// same as above

// Start Customizable Email Information
// Change the information in quotes below to fit your needs

$rec_email = "sales@xxxxxxxxx.co.nz, $email"; // who do you want to send this email to
$subject = "Canterbury Trellis Order Request  -  Your Order: $order  -  Our Ref: $ref_no"; // this is the subject line of the email


$html .="<img src='logo.gif'><br/><br />";


// Begin the HTML code - and display the place the form was sent from
$msg_body = "<html><head></head><body>";
$msg_body = "<font face=\"Verdana\" size=\"2\">";


// Display the information filled out in the contact form

//$html .= "<b><font face=\"Verdana\" size=\"2\">Company:</b>  $company<br>";
//$html .= "<b>Branch:</b>   $branch<br>";
$html .= "<b><font face=\"Verdana\" size=\"2\">Name:</b>  $name<br>";
//$html .= "<b>Order Number:</b>  $order<br>";
$html .= "<b>Reference Number:</b>  $ref_no<br>";
$html .= "<b>Phone:</b>  $phone<br>";
$html .= "<b>Cell:</b>  $cell<br>";
$html .= "<b>Requred By:</b>  $required<br>";
$html .= "<b>E-Mail:</b>  <a href=\"mailto:$email\">$email</a><br>";
$html .= "<b>Notes:</b>  $message<br>";

$html .= "<hr width=\"100%\" size=\"1\" color=\"#333333\"><br>";

$html .= "<font face=\"OCR\" size=\"1\">&nbsp; &nbsp; Wide &nbsp; &nbsp; &nbsp; &nbsp; Deep &nbsp; &nbsp; &nbsp; high &nbsp; &nbsp; Base &nbsp; &nbsp; &nbsp; &nbsp; S-Lip &nbsp; &nbsp; Wood &nbsp; &nbsp; Leg &nbsp; &nbsp; Price<br>";
$html .= "<b><font face=\"Lucida Console\" size=\"2\">Item &nbsp;1 =</b>   $item1<br>";
$html .= "<b>Item &nbsp;2 =</b>   $item2<br>";
$html .= "<b>Item &nbsp;3 =</b>   $item3<br>";
$html .= "<b>Item &nbsp;4 =</b>   $item4<br>";
$html .= "<b>Item &nbsp;5 =</b>   $item5<br>";
$html .= "<b>Item &nbsp;6 =</b>   $item6<br>";
$html .= "<b>Item &nbsp;7 =</b>   $item7<br>";
$html .= "<b>Item &nbsp;8 =</b>   $item8<br>";
$html .= "<b>Item &nbsp;9 =</b>   $item9<br>";
$html .= "<b>Item 10 =</b>  $item10<br>";
$html .= "<b>Item 11 =</b>  $item11<br>";
$html .= "<b>Item 12 =</b>  $item12<br>";
$html .= "<b>Item 13 =</b>  $item13<br>";
$html .= "<b>Item 14 =</b>  $item14<br>";
$html .= "<b>Item 15 =</b>  $item15<br>";
$html .= "<b>Item 16 =</b>  $item16<br>";
$html .= "<b>Item 17 =</b>  $item17<br>";
$html .= "<b>Item 18 =</b>  $item18<br>";
$html .= "<b>Item 19 =</b>  $item19<br>";
$html .= "<b>Item 20 =</b>  $item20<br>";
//$html .= "<b><font face=\"Verdana\" size=\"2\">$trade Total = </b>  $total.00<br><br>";
$html .= "<b><font face=\"Verdana\" size=\"2\">Total = </b>  $total.00<br>";
$html .= "<hr width=\"100%\" size=\"1\" color=\"#333333\">";

// Account payment details
$html .= "<b><font face=\"Verdana\" size=\"2\">Online payments can be made to:</b><br>";
$html .= "Canterbury Trellis Ltd<br>";
$html .= "Bank: Westpac<br>";
$html .= "Account Number: xx-xxxx-xxxxxx-xxx<br>";
$html .= "Refernce Number:  $ref_no<br>";


// Add a little information about the person who sent this message
$html .= "<hr width=\"100%\" size=\"1\" color=\"#333333\"><br>";
$html .= "<b>IP Address:</b> $REMOTE_ADDR<br>";
$html .= "</font></body></html>";


//file to attach
$fileatt2 = 'images/logo.gif';//put the relative path to the file here on your server
$fileatt_name2 = 'logo.gif';//just the name of the file here
$fileatt_type2 = filetype($fileatt2);
$file2 = fopen($fileatt2,'rb');
$data2 = fread($file2,filesize($fileatt2));
fclose($file2);

// Generate a boundary string that is unique
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/alternative;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"<font face=Arial>" .
$html."\r\n";
$message .= "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";


// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// Base64 encode the file data
$data2 = chunk_split(base64_encode($data2));

// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: image/gif;\n" . // {$fileatt_type}
" name=\"{$fileatt_name2}\"\n" .
"Content-Disposition: inline;\n" .
" filename=\"{$fileatt_name2}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data2 . "\n\n" .
"--{$mime_boundary}--\n";


// Send the message
mail($to, $subject, $message, $headers);

?>
Bazz2002
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Oct 17, 2011 11:36 pm

Re: PHP Post removes spaces from strings

Postby lokanath7 » Tue Oct 18, 2011 2:27 am

in html or php statement if u give spaces more than once it will neglect the extra spaces and deduce to one...if u really want to give spaces then instead of giving blank spaces give "&nbsp;"

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

it will show 5 spaces.
lokanath7
New php-forum User
New php-forum User
 
Posts: 139
Joined: Mon Nov 15, 2010 12:11 am

Re: PHP Post removes spaces from strings

Postby Bazz2002 » Tue Oct 18, 2011 12:27 pm

Hi thanks for that, however these extra spaces are in the strings "item1" being passed to the email software, embedding "&nbsp;" within a string does not work and only shows as "1234 &nbsp; 1234",
is there not a "hard space" that isn't removed? Side note: the spaces are required to align the data in the strings as some of the data is of different lengths.

Example:
"1000 120 1100 Yes No 120 $1500" next string may be
"100 10 110 No No 0 $44"

Remember each of these strings are not individual numbers or words, the Flash software that creates the strings displays them on the web page correctly but when passed to the mail software listed here does not.
Bazz2002
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Oct 17, 2011 11:36 pm

Re: PHP Post removes spaces from strings

Postby lokanath7 » Wed Oct 19, 2011 2:05 am

if it is only the allignment problem then u can solve it by some designing change...
u can 1st explode those data with " "(blank space) and the array u get, place all those array value in a table format to display it in better way.
lokanath7
New php-forum User
New php-forum User
 
Posts: 139
Joined: Mon Nov 15, 2010 12:11 am


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron