Howdy... 😉

I have a survey form that I get the data and send the result in an email to the owner... Everything works fine, but I'd like to add a TAB, but somehow it is not working quite right...

This will be the simplified version...

<?
	// testTab.php
	$str1 = "Question 1) Blah Blah...";
	$str2 = "Answer A) Blah Blah...";

$CR = "<BR>";
$TAB = "\t";

$output = $str1 . $CR . $TAB . $str2;

echo($output);
?>

I am expecting this to output like this...

Question 1) Blah Blah...
     Answer A) Blah Blah...

but I get this instead...

Question 1) Blah Blah...
Answer A) Blah Blah...

This is the whole script...

<?php
	// surveyMail.php

$message = "";
$headers = "";
$output = "";
//	$CR = "\r";
	$CR = "<BR>";
	$TAB = "\t";
//	$TAB = chr(9);
	$date = date("m/d/Y   H:i:s");

import_request_variables('P');

$headers .= "From: New_Survey_Result\n";
$headers .= "Reply-To: $email\n";
$headers .= "X-Mailer: PHP/\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";

$message .= "------------------------------" . $CR;
$message .= "Personal Information" . $CR;
$message .= "------------------------------" . $CR;
$message .= "Name  : $name" . $CR;
$message .= "Email : $email" . $CR;
$message .= "Age   : $age" . $CR;
$message .= "------------------------------" . $CR . $CR;
$message .= "------------------------------" . $CR;

for ($i = 1; $i <= 9; $i++)
{
	$message .= stripslashes(${"q" . $i}) . $CR . $TAB . stripslashes(${"a" . $i}) . $CR . $CR;
}

$message .= "------------------------------" . $CR;
$message .= $date .$CR;
$message .= "------------------------------" . $CR;

$send = mail($owner, "New Survey Result by $name", $message, $headers);

if ($send == true)
{
	$output = "message=$message&emailSent=true";
}
else
{
	$output = "message=$message&emailSent=false";
}

echo($output);

$output .= "\n\n\n";

$FileName = "./sentEmail.txt";
$FilePointer = fopen($FileName, "a+");

fwrite ($FilePointer, $output);
fclose ($FilePointer);
?>

As you can see I am appending each result to the text file called 'sentEmail.txt'... The thing is that the text file has the desired format... It is just now showing up right within the browser...

If I change this line...

$headers .= "Content-type: text/[b]html[/b]; charset=iso-8859-1";

to be this, it does show me the correct TAB character...

$headers .= "Content-type: text/[b]plain[/b]; charset=iso-8859-1";

But with the 'plain', the email does not show up correctly... The output that I have adding within the for loop do not show up correctly if I set it to 'plain', which I have no idea why, but with 'html' I get to see the correct output without the TAB character...

Anybody can shed some light on me??? 🙁

Thank you for your time... 😉

    HTML never had a TAB character. All whitespace in HTML (except for what appears in pre-formatted blocks) is condensed down to a single space character.

    You could either get high-tech with stylesheets, or just stick in a few &amp;nbsp; entities where the tab should go.

      Your last sentence is kinda confusing, but here are my thoughts:

      Browsers do not allow multiple white space characters in HTML unless they are wrapped up in the <pre> tags. I think the reason why your file doesn't display the tab with the 'content/type' header set to HTML is because the browser is interpreting the tab as mulitple white spaces thus turning them into a single space. You might need to have two outputs... you could add a line near the end of the script to replace the header type to 'plain' and assign the new string to $output2file:

      $output .= "\n\n\n";
      
      // add this line
      $output2file = str_replace('text/html', 'text/plain', $output)
      
      $FileName = "./sentEmail.txt";
      $FilePointer = fopen($FileName, "a+");
      
      fwrite ($FilePointer, $output2file); // and change the variable here
      fclose ($FilePointer);
      ?>

      I hope that helps.

        Thank you, guys... Much appreciate your help... 😉

        I have already tried $TAB = "& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;"; and it didn't do the job... I thought this might do the job but it didn't, and Weedpacket and zeb kinda explained up there why... But I am curious...

        Aren't I supposed to see at least ONE space before the second line??? I thought it was like what Weedpacket and zeb has said in the beginning, but when I checked the text closely, there was NO space in front of the answer at all like this...

        Question 1) Blah Blah...
        Answer A) Blah Blah...

        I have not tried <PRE> tag yet... I don't know why, but I keep forgetting about it... 😃

        Thank you for your time, guys... Much appreciated... 😉

          it should NOT be & nbsp; it should be combined

            Oh... I just said '& nbsp;' because I only see the blank spacw without the space in between... It actually is this one...

            &nbsp;

            Thank you... 😉

              Write a Reply...