I have an app where people can fill in some data and send it to my email. The mail is sent and working fine except that the body of the mail is empty.
My method for the connection:
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if( !(buttonIndex == [actionSheet cancelButtonIndex]) ) {
NSString *post = nil;
post = [[NSString alloc] initWithFormat:@"Naam spel = %@ Uitleg= %@", spelnaam.text ,Uitleg.text];
NSLog(@"dit wordt verstuurd %@", post); //works fine!
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.myserver.nl/theemailfile.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[ NSURLConnection connectionWithRequest:request delegate:self ];
[post release];
[self displayAlert];
}
}
My php file:
<?php
$message = $_REQUEST['message'] ;
mail( "emailadres@gmail.com", "Test Message", $message );
?>
In your HTTP request, you're saying that the information you are sending in the body of the request is of the type application/x-www-form-urlencoded
, however that isn't the case. It appears to just be free-form text. You should conform to the format described in the HTML specification. You are sending a message that looks like this:
Naam spel = test Uitleg= test
You need to send something like this:
message=This+is+a+test&other=test