duanpanbo9476
duanpanbo9476
2013-03-21 11:14

电邮通过服务器

  • php
  • ios
  • xcode
  • email

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 );
?>
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答