0

I am using Xcode to create an objective c application

Is there any way to send an email, from a form of five or so text fields, so that when the user clicks the send button, it will send the data they have entered into the text fields to a pre defined email address.

I have tried searching for relevant questions already asked but a lot of the techniques used are deprecated now.

I have tried:

-(IBAction)email {
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    ([MFMailComposeViewController canSendMail]); {
        [composer setToRecipients:[NSArray arrayWithObjects:@"makingwavesswimschool@live.co.uk", nil]];
        [composer setSubject:@"Enter Subject Here"];
        [composer setMessageBody:@"Enter Message Here" isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self presentModalViewController:composer animated:YES];

    }
}

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    if (error) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                        message:[NSString stringWithFormat:@"Error %@", [error description]]
                                                       delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
        [alert show];
        [self dismissModalViewControllerAnimated:YES];
    }
    else {
        [self dismissModalViewControllerAnimated:YES];
    }
}

However this crashes to the present and dismiss modal view controller being deprecated.

Is there a way to modify this to work off of a form?

Thanks

  • Maybe have a class that can serve as the email template? Use variables and string literals to represent the pre-defined email and then when the user clicks the send button, the class can enter the user's text into the variable portions of the template. You can call another Sender class to send the contents of the email template. – HandleThatError Mar 25 '15 at 17:40
  • try this http://stackoverflow.com/questions/4942976/how-to-send-mail-from-iphone-app – LC 웃 Mar 25 '15 at 17:49
  • What techniques are deprecated? What ideas have you considered? – rmaddy Mar 25 '15 at 17:49
  • @HandleThatError, that sounds like a good idea but out of my ability to be honest! Thanks for your help. anish Thanks, but that is the method I have tried before and part of that is deprecated, and I dont know how to apply it to a form. rmaddy I have tried the method in the link above your post. – user3641747 Mar 25 '15 at 17:58
  • If you are having trouble with a specific implementation, then update your question with the details of what you have tried and the problems you are having. – rmaddy Mar 25 '15 at 18:03
  • I have edited the original post now, thnaks – user3641747 Mar 25 '15 at 18:09
  • Lookup the deprecated methods in the docs and use the new methods it tells you to use. – rmaddy Mar 25 '15 at 18:12

0 Answers0