2013-03-21 11:14
浏览 17


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:

 $message = $_REQUEST['message'] ;
 mail( "emailadres@gmail.com", "Test Message", $message );
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpxf81245
    dpxf81245 2013-03-21 11:23

    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:

    点赞 评论