Sending an email containing user-entered data
I am developing an app for a business. This app is essentially a product order app that takes the products from a database file. When the file is selected, it mov开发者_如何学Pythones to a page with options of quantity, length, color, etc. Then, if the purchase is confirmed, it goes to another page to fill out user information.
Is there a way to print the details the user inputs from both pages to an email and send that email to a specific billing address? To the user it is just simply hitting the confirm button, but in the background it sends an email with all this info. I have found different forums talking about email from an iPhone app but none seem to work the way I need them to.
You can add any text to mail composer like this:
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
[mailController setMessageBody:[NSString stringWithFormat:@"User %@ ordered %d of %@ at a price of %f",
orderCustomer,
orderQuantity,
orderItem,
orderPrice]
isHTML:NO];
[self presentModalViewController:mailController animated:YES];
[mailController release];
As you can see, you can also insert html into the mail message body if you want your order to be formatted nicely.
Yes it is. One simple method for capturing user input is to use a screen shot. Then attaching it to an email. You can render the screen to pdf or image format.
Something like:
//draw main window in image context
UIWindow *window=[[[UIApplication sharedApplication] windows] objectAtIndex:0];
[[window layer] renderInContext:context];
//convert to UIImage
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//clean up
UIGraphicsEndImageContext();
//return
return image;
As for sending an email in the background you will need to use a third party library. MFMailComposeViewController can be used to send an email from iOS but it requires the user to confirm the email dialog.
精彩评论