Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Submission - Textfeilds with commas

Status
Not open for further replies.

Muppsy007

Programmer
Apr 4, 2003
98
NZ
Hello,

I have some forms that send an email to me using Jack's php formmail script embedded in a confirmation page.

This worked fine before changing to a new dedicated server with standard php setup on it.

Now, whenever a user enters data that contains a comma into a text feild, the form simply doesn't send. Take the comma out, and it works.

As this script worked fine on our old host, I am thinking that this is an issue that can be resolved in php.ini.

Has anyone heard of this before?

Thanks
Aaron
 
nope, where exactly does this comma create a trouble? in the body of the mail? or in the To field or From field???

Known is handfull, Unknown is worldfull
 
could you post some code to see it? specialy the form and the sendmail command.
 
It's probably a quoting issue, but without a little more information I don't think anyone is going to be able to help. You might try printing out your $_REQUEST variables to see what's screwing up.
 
Hi Guys, here are the particulars, and it's really weird.

The form has quite a few text feilds and text areas. I have done some more testing and have discovered that the problem ONLY occurs when 2 or more text feilds have commas in them.

It doesn't matter what combination, if 2 or more feilds have commas in them, the mail won't doesn't arrive. Take the commas out, leaving only one feild with a comma in it, and it arrives fine.

Text Areas are fine, add as many commas as you like.

I have outputted the content and headers to the page, everything is normal, including the recipient.

I also placed a small mail() script right under where the formmail should be sent as follows:

mail($recipient, $subject, $message, $headers); // Orig Send
mail('me@me.com','Report','OK'); // Debug Send

The debug works fine, but if you enter commas into 2 or more text feilds, and change 'OK' to $message, nothing is sent at all. Even though I can output all the variables on screen using echo in the script.

Here is the code that sets $message:

Code:
$message  = "This is a multi-part message in MIME format.\n";
   $message .= "\n--".$ob."\n";
   $message .= "Content-Type: multipart/alternative;\n\tboundary=\"".$ib."\"\n\n";
   $message .= "\n--".$ib."\n";
   $message .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
   $message .= "Content-Transfer-Encoding: quoted-printable\n\n";
   
   //Add normal header//////////////////////////////////////////////////////
   $message .= "Below is the result of your feedback form.  It was submitted by<br>";
   $message .= "(<a href=\"\"mailto:" . $email . ">" . $email . "</a>) on " . $orderTime . "<br>";
   $message .= "---------------------------------------------------------------------------<br><br>";
   //////////////////////////////////////////////////////////////////////////////////////////////
   
   $message .= $content."\n\n"; 
     
   $message .= "\n--".$ib."--\n";
   if ($attachment_name && !$attachment_sent) {
      $message .= "\n--".$ob."\n";
      $message .= "Content-Type: $attachment_type;\n\tname=\"".$attachment_name."\"\n";
      $message .= "Content-Transfer-Encoding: base64\n";
      $message .= "Content-Disposition: attachment;\n\tfilename=\"".$attachment_name."\"\n\n";
      $message .= $attachment_chunk;
      $message .= "\n\n";
      $attachment_sent = 1;
   }
   
   $message .= "\n--".$ob."--\n";
   
   mail($emed_recipient, $emed_subject, $message, $headers);

Like I said, the wierd part is, sending only fails when two or more feilds have commas in them. If only one feild has a comma, no problem.

 
Sorry, not sure what you mean by $_REQUEST variables. I have tested by output the $_POST variables that are passed from the form to the script, and they come out perfectly fine, including the ones with the commas in them.

There is also another script that sends an autoresponse to the user. This autoresponse also includes some of the variables that are passed. This comes through just fine, even with the commas there.

sleipnir214 - It doesn't matter which feilds you put commas in, as long as two or more have them, the email goes AWOL.

Go back and take the commas out of all but one feild, and it's sweet.
 
can you run the script and post the screen output obtained from the command

Code:
print_r($_POST);

you might also want to change line 11 (quote marks have gone wrong)
Code:
   $message .= "(<a href='mailto:$email'>$email</a>) on $orderTime <br>";

for readability i would also suggest changing the "\n" to "\r\n"
 
Thanks jpadie,

Tried print_r($_POST);. All the passed variables display, perfectly. Even the feilds that had commas in them, display just as they were entered.

Tried changing the quotes on line 11 as you suggested. But this turns the entire email content into a mailto: link.

And I can't substitute "\n" for "\r\n". I am running on FreeBSD, which means that if I terminate lines witn "\r\n", html headers do not send correctly.
 
my apologies on the FreeBSD point.

on my installation, the line 11 substitution works fine and i get a mailto link as well as the email address in text. using the double escaped double quotes in your original code meant the entire line was cut off just after the href. i thought this might be pertinent to your comma issue as the next line but one appears to have the field input. in line 11 why have you got \"\" and not just one escaped.
 
Well, now you're just down to debugging 101: simplify, simplify, simplify.

Change your message to a simple piece of text with no variable substitutions. If that works, try sending the email without attachments. Etc, etc, etc.
 
OK thanks, I'll try to track down exactly where it starts.

Sorry I can't be much more help, it's a downloaded script so I'm not overly familiar with it.

Will let you know..
 
we can be of more help if you supply the form that gets filled in...
 
Muppsy007 said:
And I can't substitute "\n" for "\r\n". I am running on FreeBSD, which means that if I terminate lines witn "\r\n", html headers do not send correctly.

Use of "\r\n" makes the script fail? As the SMTP spec states:

The term CRLF, in this document, refers to the sequence of the two ASCII characters CR (13) and LF (10) which, taken together, in this order, denote a line break in RFC 822 mail.

That's an odd behavior. What mail server is running on your system?

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
qmail.

This is something I found out on the PHP.net site after we changed hosts. It's sucks I know, but very true.

Basically all the html email sent using mail() would come through to all email clients as code only. eg. you could see the html code.

As soon as I changed all CRLF to "\n" instead of "\r\n", the emails came through to the very same clients perfectly formatted as before.

Pretty Odd alright, just like this one.

Still working on simplifyin the above code. Thanks guys

Aaron
 
Aaron

here is a cut and paste (with minor mods) of an email form submission engine I use for debugging forms. it takes all the variables within the form (including the buttons) and emails them using the mail function.

just
+edit this file to provide the right email address and terminator
+take your online form and point the action (assume the method is post?) at this file.
see what happens. if it is still bust then debugging your code might not be the solution...

Code:
<?
if (!isset($_POST))
{die ("this script has not had a post variable passed")}

$terminator = "\r\n";  //change this as you wish
$emailfrom = "user@domain.com";
$to = "user@domain.com"; //remember to change this to your mail address
$message ="";
$htmlmessage = "<html><body><table>";
foreach($_POST as $key=>$val)
{
	$htmlmessage .= "<tr><td width=\"30%\">$key</td><td width=\"70%\">$val</td></tr>$terminator";
	$message . = "Value of $key was $val $terminator";
}
$htmlmessage .= "</table></body.</html>";

$baseheaders = "From: $from  $terminator";

$headers = "MIME-Version: 1.0 $terminator"; 

//unique boundary 
$boundary = uniqid("HTMLDEMO"); 

//tell e-mail client this e-mail contains//alternate versions 
$headers .= "Content-Type: multipart/alternative" . 
   "; boundary = $boundary $terminator $terminator"; 

//message to people with clients who don't 
//understand MIME 
$headers .= "This is a MIME encoded message. $terminator"; 

//plain text version of message 
$headers .= "--$boundary $terminator" . 
   "Content-Type: text/plain; charset=ISO-8859-1 $terminator" . 
   "Content-Transfer-Encoding: base64 $terminator"; 
$headers .= chunk_split(base64_encode($message)); 

//HTML version of message 
$headers .= "--$boundary $terminator" . 
   "Content-Type: text/html; charset=ISO-8859-1 $terminator" . 
   "Content-Transfer-Encoding: base64 $terminator"; 
$headers .= chunk_split(base64_encode($htmlmessage)); 

$headers = $baseheaders . $headers;
mail($to,$subject,$message,$headers);
?>
 
Thanks a bunch jpadie,

Will have a go and let you know.

Cheers again
Aaron
 
Hi Again guys,

I tracked down the problem.

Basically, the script goes through and adds the form variables to the $message variable in the order specified on the form.

But there is also a reserved field part of the function that lists the names of all the fields that we don't want on the email.

The line of code that cause the problem was this:

Code:
/* First add the header to the top of the email */
$message = "Below is the result of your feedback form.  It was submitted by<br>";
$message .= "(<a href=\"mailto:$email\"> $email </a>) on $orderTime <br>";
$message .= "---------------------------------------------------------------------------<br><br>";

This is something I added myself, and it just adds a Matt's formmail style intro to the email. I did try the same code in diferent ways, included adding CR to the end of each line. But nothing.

I found that if I commented this block out, the formmail would send fine regardless of how many commas were in the field.

I was unable to work out why, so I just basically started from scratch, borrowing the parts of the original code that I needed (like the ordering and reserved fields) and tried again.

It seems to work fine now.

There were a few other functions there to check validity etc, so maybe something else was a work here.

I don't these extra functions as I use JS for validation and this is a mail script to send internal anyway.

Thanks for your help guys. But this one is still a bit of a mystery.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top