如何将用户输入的详细信息发送到 iOS 中的电子邮件?
How to send user entered details to email in iOS?
我正在使用 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];
}
}
}
简单回答:您不能在 iOS 应用程序中执行此操作。
解决方法 : 你需要在服务器端设置邮箱。每当用户发送任何请求时,服务器都可以从后端邮寄此内容。据我所知,这是实现您要求的唯一方法。
我可以根据 URL 假设您的服务器使用 php。请参考以下 link 到后端 php 服务器的邮件。
http://www.w3schools.com/php/func_mail_mail.asp
希望对您有所帮助。
我正在使用 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];
}
}
}
简单回答:您不能在 iOS 应用程序中执行此操作。
解决方法 : 你需要在服务器端设置邮箱。每当用户发送任何请求时,服务器都可以从后端邮寄此内容。据我所知,这是实现您要求的唯一方法。
我可以根据 URL 假设您的服务器使用 php。请参考以下 link 到后端 php 服务器的邮件。
http://www.w3schools.com/php/func_mail_mail.asp
希望对您有所帮助。