Jump to content

Can't insert tab into text file - just won't show!


mihomes

Recommended Posts

In the below code I am sending myself an email in plain/text (a customer order to be exact).  $message comes in as plain text as shown here with the %%variables%% being replaced with their actual values before being sent to the function:

 

Date: %%ORDERDATE%%
Invoice ID: %%INVOICE%%
Coupon: %%COUPON%%
IP: %%IP%%

<!-- BEGIN CARTITEMS -->
%%QUANTITY%%***%%PRODUCTCODE%%***%%NAME%%***%%PRICE%%***%%TOTAL%%
<!-- END CARTITEMS -->

Out of stock items (these will ship separately at no additional charge when they become available):

NONE

Customer Comments:

%%COMMENTS%%


Subtotal: %%SUBTOTAL%%
Discount: -%%DISCOUNT%% (Coupon '%%COUPON%%')
Shipping: %%TOTALSHIPPING%%
Total: %%GRANDTOTAL%%


Ship to / Project Location:

%%FIRSTNAME%% %%LASTNAME%% (%%EMAIL%%)
%%COMPANY%%
%%ADDRESS%%
%%ADDRESS2%%
%%CITY%%, %%STATE%%  %%ZIP%%
%%PHONE%%

Thank you for your quote request.  If the.....

 

Now, in the function I am sending myself the email.  I use string replace to remove the '<!-- BEGIN CARTITEMS -->' and '<!-- END CARTITEMS -->' lines because if I don't then every product is surrounded by them.  That works absolutely fine and all products end up listed one per line in the email.

 

The problem is adding in a tab.  I use the same string replace and replace every * with \t.  It removes the *'s, but there is no tab inserted whatsoever.  If I switch the code to \n then it works and gives new lines for each *.  For whatever reason I cannot get a tab inserted.  What am I doing wrong!?

 

function SendPHPMail($sendtoemail, $from, $fromemail, $additional, $subject, $message, $html){

$eol="\n"; 
$headers  = "MIME-Version: 1.0".$eol;
$headers .= "Content-type: text/plain; charset=utf-8".$eol;
$headers .= "From: $from <$fromemail>".$eol;
$headers .= "Reply-To: $from <$fromemail>".$eol; 
if ($additional != ""){
	$additional = explode(',',$additional);
	foreach($additional as $value)
		$headers .= "Cc: $value".$eol;
}

$remove1 = "<!-- BEGIN CARTITEMS -->\n";
$remove2 = "<!-- END CARTITEMS -->\n";
$ast = "*";

$message = str_replace($remove1, '', $message);
$message = str_replace($remove2, '', $message);
$message = str_replace($ast, "\t", $message);

$success = mail($sendtoemail, $subject, $message, $headers);
}

Link to comment
Share on other sites

I think the tab is probably there, but your mail client doesn't want to display the extra whitespace.

 

I don't think thats the case.  I can respond to the email which isnt showing tabs (goes back to another email account of mine) and then receive it on the same email client and it will show the tabs wherever I enter them.  I viewed properties as well and it is text/plain format just like the one I sent.

Link to comment
Share on other sites

I've had inconsistent experience with tabs in emails too.  Why not just use 4 spaces instead of the tab character?

 

Well, there are columns - qty, id, name, price, total for any number of product which the customer is ordering.  Using tabs would make it somewhat easier to align them in a plain/text email.  I guess I am going to have to write a function to align everything using spaces.

Link to comment
Share on other sites

You can use str_pad to pad everything with spaces.

 

Well, after doing some more research it turns out the tabs are inserted its just outlook express is deciding not to show them unless I specifically tell it to read all emails in plain/text through the options.  So, I think str_pad would be a good way to go here as far as aligning these products.  Now, I am not all too familiar with php, but I get the gist of it pretty good... I just don't know any of the function names and what to look for, for what I want to do.  Here is an example order email and what I am thinking :

 

Date: Wed Dec 31, 2008 10:41 am
Invoice ID: 5B92BBD94
Coupon: hohoho
IP: 111.111.111.111

<!-- BEGIN CARTITEMS -->
2     W1245     Widget 5 BLUE     $62.55     $125.10
<!-- BEGIN CARTITEMS -->
3     W4859     Widget 34 RED     $9.00     $27.00
<!-- END CARTITEMS -->

Out of stock items (these will ship separately at no additional charge when they become available):

NONE

Customer Comments: and so on.......

 

The above is stored as $message before sending the email to myself.  Basically all I need to do here is use str_pad for each of the variables - qty, id, desc, price, total - on each line until <!-- END CARTITEMS --> is reached.  So, in other words read in each one, insert the correct str_pad, go to next and so on... when everything is done I can use str_replace to remove the <!-- BEGIN CARTIEM --> and <!-- END CARTITEM -->.  Result would be $message with the cart contents aligned nicely with certain whitespaces to the left thus aligning all the cart items in the email.

 

Any help on this one or is there an easier way?  I can also add in delimiters before each cart variable if that would make it easier.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.