我创建了一个联系我们表单,表单中有三个文本字段(姓名、电子邮件、电话号码),我的表单中有 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