我有一個應用程序,人們可以填寫一些數據並將其發送到我的電子郵件。郵件發送正常,但郵件正文爲空。通過服務器發送電子郵件
我爲連接方法:
-(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];
}
}
我的PHP文件:
<?php
$message = $_REQUEST['message'] ;
mail("[email protected]", "Test Message", $message);
?>
您需要隔離,這是否是您的客戶端應用程序,或者是否這是你的服務器。你可以控制兩個,是嗎?首先,在做'NSURLConnection'之前確保「'postData'」不是null(例如,在Xcode中設置斷點)。 – 2013-03-21 11:21:39
你爲什麼不使用內置郵件API發送郵件? – 2013-03-21 11:23:46
使用內置郵件Api,用戶必須啓用電子郵件帳戶 – 2013-03-21 11:56:42