tags:

views:

173

answers:

1

I'm letting my App's user send email from within the app to share some content on myserver. To do so I need to include a button with two bits of data and I want to use POST to keep it somewhat hidden. I've decided to add an html form using POST and two hidden fields in the email rather, like so:

NSString *buttonCode = [NSString stringWithFormat:@"<form method='post' action='http://www.example.com/iphone/nifty.php'&gt;
 <input type='hidden' name='dataOne' value='%@'>
 <input type='hidden' name='dataTwo' value='%@'>
 <input type='submit'value='Submit'></form>",dataOne, dataTwo];
NSString *emailBody = [NSString stringWithFormat:
        @"<b>%@ - %@</b>\n\n<HR WIDTH=200 SIZE=2 COLOR=#755f0f ALIGN=CENTER>\n Here is a email:<br><br>%@", 
         dateString, 
         timeString,
         buttonCode];
[picker setMessageBody:emailBody isHTML:YES];

I've confirmed by looking at the raw source of the email that the form is constructed correctly and I've copied and pasted it into a web page and it works.

So here is the problem. When I click on the button in the received email (using apple's mail client) the dataOne and dataTwo variables don't get passed to my server.

Is there a better way to do this or is the issue with my mail client?

====== update ==========

I think this may be related to the line the iPhone adds to the email:

--Apple-Mail-1--23863057 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit

When I add enctype="text/html" to the form in the test html on the server as mentioned above the variables are not received.

Is there a way to alter this from the iPhone and send it another way?

A: 

The enctype just tells the mail client that the email contains HTML, the problem is that your mail client is dropping the fields.

Henri Watson
When I copied and pasted the code from the email (using raw source) into a web page the code works fine. Perhaps it is just not possible to send a form using POST using MFMailComposeViewController.
Michael
You said the form showed up in it's entirety in the email received. Putting the form on a test form on a website and putting it on the email will give you completely different results because you are skipping many steps by putting it on the website. If you posted the raw source of the email received it would really help.
Henri Watson
Thanks Henri,Here is the PasteBin of the full email http://pastebin.com/1mxJjuGa
Michael
I've since fallen back to GET and I create a hash in our DB that prevents leaching. That's working for us now but I would like the resolve this issue in case anyone else wants to do this and for future use.
Michael
As far as I can see in the pastbin you sent, the email is in it's entirety and nothing was stripped out on the iPhone side. Your problem is like I said the email client.
Henri Watson
Thanks for your input.
Michael