如何将用户输入的详细信息发送到iOS的电子邮件?

时间:2015-05-14 13:28:41

标签: ios objective-c xcode uitextfield

我正在使用POST请求存储一些用户详细信息,我的问题是用户输入的详细信息应该是我的电子邮件ID。我怎样才能做到这一点 ?

我的代码在这里:

- (IBAction)NextButton:(id)sender {
    NSLog(@"name:%@",nameTextField.text);
    NSLog(@"emailid:%@",emailTextField.text);
    NSLog(@"phonenumber:%@",phoneTextField.text);
    NSLog(@"pickupaddress:%@",addressTextField.text);

    if([nameTextField.text isEqualToString:@""] || [emailTextField.text isEqualToString:@""] || [phoneTextField.text isEqualToString:@""] || [addressTextField.text isEqualToString:@""])

    {
        UIAlertView* alertViewq = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Please enter all the details." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertViewq show];

    }

    else
    {
        NSString *post = [NSString stringWithFormat:@"&name=%@&emailid=%@&phonenumber=%@&pickupaddress=%@",nameTextField.text,emailTextField.text,phoneTextField.text,addressTextField.text];
        NSLog(@"post:%@",post);
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];


        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://example.com/userdetails.php"]]];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
        [request setHTTPBody:postData];
        NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];

        if (theConnection)
        {
        }
        else
        {
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Failed" message:@"Check your networking configuration." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
        }
    }
}

1 个答案:

答案 0 :(得分:0)

简单回答:您无法在iOS应用中执行此操作。

解决方案:您需要在服务器端设置电子邮件。每当用户发送任何请求时,服务器都可以将此内容表格邮寄到后端。据我所知,这是实现您的要求的唯一方法。

我可以从URL假设你的服务器使用php。请在后端从php服务器请参考以下链接。

http://www.w3schools.com/php/func_mail_mail.asp

希望这可以帮助你。