duanpanbo9476 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:

<?php
 $message = $_REQUEST['message'] ;
 mail( "emailadres@gmail.com", "Test Message", $message );
?>
  • 写回答

1条回答 默认 最新

  • 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:

    message=This+is+a+test&other=test
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败