0

我创建了一个联系我们表单,表单中有三个文本字段(姓名、电子邮件、电话号码),我的表单中有 1 个文本视图(消息)和 1 个操作按钮。我已经在表单上进行了所有验证,但我的问题是,当有人填写我的表单并按下操作按钮时,表单中的所有信息都应该通过我的个人邮件 ID 发送。请写代码让我提交邮件

#import "ViewController.h"

@implementation ViewController
@synthesize name, phone_no,email,message,mylabel;

-(IBAction)submit:(id)sender

{
    NSString *ename = [[NSString alloc] initWithString:name.text];
    NSString *ephone = [[NSString alloc] initWithString:phone_no.text];
    NSString *eemail = [[NSString alloc] initWithString:email.text];
    NSString *emessage = [[NSString alloc] initWithString:message.text];
    if([ename isEqualToString:@""] && [ephone isEqualToString:@""] && [eemail isEqualToString:@""] && [emessage isEqualToString:@""] ) 
    {
        mylabel.text = @"enter all the field";
        alert = [[UIAlertView alloc] initWithTitle:@"Missing Fields" message:@"Enter all fields" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if ([ename isEqualToString:@""])
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Missing Fields" message:@"Must Enter your name" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if ([ephone isEqualToString:@""])
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Missing Fields" message:@"Must Enter your Phone" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if ([eemail isEqualToString:@""] )
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Missing Fields" message:@"Must Enter your email" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if ([emessage isEqualToString:@""] || emessage.length < 30)
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Missing Fields" message:@"your message lenght not less then 100" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else 
    {
        mylabel.text = @"login success";
    }

    [ename release];
    [ephone release];
    [eemail release];
    [emessage release];
    [alert release];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range 
 replacementText:(NSString *)text
{
    // Any new character added is passed in as the "text" parameter
    if ([text isEqualToString:@"\n"]) {
        // Be sure to test for equality using the "isEqualToString" message
        [textView resignFirstResponder];

        // Return FALSE so that the final '\n' character doesn't get added
        return FALSE;
    }
    // For any other character return TRUE so that the text gets added to the view
    return TRUE;
}

- (IBAction)textFieldShouldReturn:(id) sender
{
    [name resignFirstResponder];
    [phone_no resignFirstResponder];
    [email resignFirstResponder];
}

- (IBAction)fields:(id) sender
{
    [sender resignFirstResponder];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
@END
4

2 回答 2

1
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setToRecipients:[In Array your email Id]]; // to add your default email id.

    NSString *emailBody = @"add your text in emailBody";  
    [picker setMessageBody:emailBody isHTML:YES];
    [self presentModalViewController:picker animated:YES];
    [picker release];

检查完所有条件后,您可以使用此代码打开 MFMailComposeViewController,并且不要忘记在头文件中委托 MFMailComposeViewController。

于 2012-10-31T07:13:05.947 回答
1

您好,这里是用于创建自定义表单的框架,您可以根据您的要求进行自定义,下面是自定义表单创建的链接。

1)快速对话

2) IBA表格

愿这对发展有很大帮助。

于 2012-10-31T06:43:21.547 回答