i want to send a Mail in my app with an .PHP file as Attachment:
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@""];
[mailViewController setMessageBody:@"" isHTML:NO];
mailViewController.navigationBar.tintColor = [UIColor blackColor];
NSData *myData = [NSData dataWithContentsOfFile:[self getScriptPath]];
NSString *fileName = @"upload.php";
[mailViewController addAttachmentData:myData mimeType:@"text/html" fileName:fileName];
[self presentViewController:mailViewController animated:YES completion:nil];
[mailViewController release];
}
else
NSLog(@"Device is unable to send email in its current state.");
The Mail is being sent, but without the attachment!…
I bet your
[self getScriptPath]method return an invalid path, or a path to a non-existing file, and thus[NSData dataWithContentsOfFile:...]probably returnnil.You should use a breakpoint or NSLog to check the value returned by
getScriptPathand fix it accordingly.For example if you embedded the
"upload.php"file in your application (you added it in your Xcode project, along with the other resources of your application), you should use this to get the valid path of your script file in your bundle:See the Bundle Programming Guide documentation for more info.