2015-05-14 73 views
0

我正在使用POST請求存儲一些用戶詳細信息,我的問題是用戶輸入這些詳細信息的任何詳細信息都應該到達我的電子郵件ID。我怎樣才能做到這一點 ?如何將用戶輸入的詳細信息發送至iOS中的電子郵件?

我的代碼是在這裏:

- (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]; 
     } 
    } 
} 

回答

0

答案很簡單:你不能iOS應用內做到這一點。

解決方案:您需要在服務器端設置電子郵件。每當用戶發送任何請求時,服務器都可以將這些內容郵寄給後端。據我所知,這是實現您的要求的唯一途徑。

我可以從URL假設你的服務器使用php。請參考以下鏈接從後端的PHP服務器發送郵件。

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

希望這可以幫助你。

相關問題