2012-02-11 5 views
0

전자 메일을 통해 단일 전자 메일 주소로 보내려는 텍스트 필드 (5 개의 필드)로 구성된 연락처 양식이 있습니다. xCode에서 어떻게합니까?연락처 양식 보내기 전자 메일의 필드

+1

가 이미 http://stackoverflow.com/questions/7087199/xcode [SO] (전에 대답 -4-ios-send-an-email-using-my-app-inside-my-app) –

답변

0

링크 된 게시물의 답변은 비슷하지만 canSendMail을 이미 확인 했으므로 코드를 추가하고 있습니다. 이메일에 다른 내용을 쉽게 추가 할 수 있도록 주석이 달린 코드도 남겨 두었습니다. 당신은이 코드를 사용하는 무료 앱 QCount을 가지고

아이폰 OS (5)을 대상으로하는 경우이 실질적으로 쉽다는 것을

참고. 사실, 나는 당신의 .H에서, 나는 http://itunes.apple.com/ng/app/qcount/id480084223?mt=8

즐기세요 :-) 내 복사 및 붙여 넣기에서 사용자 정의 모든 것을 박탈

데미안

희망 : 당신의

#import <MessageUI/MessageUI.h> 

방법. m :

- (void)emailLabelPressed { // or whatever invokes your email 
// Create a mail message in the user's preferred mail client 
// by opening a mailto URL. The extended mailto URL format 
// is documented by RFC 2368 and is supported by Mail.app 
// and other modern mail clients. 
// 
// This routine's prototype makes it easy to connect it as 
// the action of a user interface object in Interface Builder. 
Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 
if (mailClass != nil) 
{ 
    // We must always check whether the current device is configured for sending emails 
    if ([mailClass canSendMail]) 
    { 
     [self displayComposerSheet]; 
    } 
    else 
    { 
     [self launchMailAppOnDevice]; 
    } 
} 
else 
{ 
    [self launchMailAppOnDevice]; 
} 
} 

-(void)displayComposerSheet { 
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
picker.mailComposeDelegate = self; 

[picker setSubject:@"Your Form Subject"]; 

// Take screenshot and attach (optional, obv.) 
UIImage *aScreenshot = [self screenshot]; 
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(aScreenshot)]; 
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:@"screenshot"]; 

// Set up the recipients. 
NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", nil]; 
// NSArray *ccRecipients = [[NSArray alloc] init]; 
// NSArray *bccRecipients = [[NSArray alloc] init]; 
// NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
// NSArray *bccRecipients = [NSArray arrayWithObjects:@"[email protected]", nil]; 

[picker setToRecipients:toRecipients]; 
// [picker setCcRecipients:ccRecipients]; 
// [picker setBccRecipients:bccRecipients]; 

// Attach an image to the email. 
/* NSString *path = [[NSBundle mainBundle] pathForResource:@"ipodnano" 
ofType:@"png"]; 
NSData *myData = [NSData dataWithContentsOfFile:path]; 
[picker addAttachmentData:myData mimeType:@"image/png" 
fileName:@"ipodnano"]; 
*/ 
// Fill out the email body text. 
// NSString *emailBody = @"Use this for fixed content."; 

NSMutableString *emailBody = [[NSMutableString alloc] init]; 
[emailBody setString: @"Feedback"]; 
// programmatically add your 5 fields of content here. 

[picker setMessageBody:emailBody isHTML:NO]; 
// Present the mail composition interface. 
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) { 
    [self presentViewController:picker animated:YES completion:nil]; 
} else { 
    [self presentModalViewController:picker animated:YES]; 
} 
} 

- (void)mailComposeController:(MFMailComposeViewController *)controller 
     didFinishWithResult:(MFMailComposeResult)result 
        error:(NSError *)error { 
if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) { 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} else { 
    [self dismissModalViewControllerAnimated:YES]; 
} 
} 

-(void)launchMailAppOnDevice { 
NSString *recipients = @"mailto:[email protected][email protected],[email protected]&subject=Hello from California!"; 
NSString *body = @"&body=Feedback"; 

NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body]; 
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]]; 
} 
1

이 질문에 걸림돌이있는 사람은 thi s 드롭 인 iOS 문의 양식.

이것은 필자의 필요에 잘 맞으며 실제로 전자 메일을 보내기 위해 PHP 구성 요소를 사용합니다. . (예를 들어 스크립트가 샘플 프로젝트에 포함되어

을 여기 Github에서에 게시 :

https://github.com/mikecheckDev/MDContactForm

+0

공유 해 주셔서 대단히 감사합니다. :-) – kernix