iosswiftuitableviewmfmailcomposer

Email formatting doesn't get information from tableView


I'm trying to get my app to send an email containing all the data collected in a View controller

here's my code

func sendemail() {
    let formatter = NSDateFormatter()
    formatter.dateStyle = .MediumStyle
    formatter.timeStyle = .FullStyle
    let dateString = formatter.stringFromDate(datePicker.date)

    var emailtext = NSLocalizedString("Pilot name : ", comment: "");
    emailtext += String(pilotsTextField.text)
    emailtext += "<br />";
    emailtext = NSLocalizedString("Aicraft : C-", comment: "");
    emailtext += String(acRegTextField.text)
    emailtext += "<br />";
    emailtext += "<br />";
    emailtext = NSLocalizedString("Passengers :", comment: "");
    emailtext += "<br />";
    for (var i=0 ; i < passengers.count; i++) {
                   let passenger = passengers[i]
        emailtext = "Name: \(passenger.paxName)"
        emailtext += "<br />";
        emailtext = "Name: \(passenger.paxWeight)"
        emailtext += "<br />";
        emailtext = "Name: \(passenger.paxEmergencyName)"
        emailtext += "<br />";
        emailtext = "Name: \(passenger.paxEmergencyPhone)"
        emailtext += "<br />";
        emailtext = "Name: \(passenger.paxDestinationComments)"
        emailtext += "<br />";
        emailtext += "<br />";
    }
    emailtext += "<br />";
    emailtext += "Date and Departure time : ";
    emailtext += dateString;
    emailtext += "<br />";
    emailtext += NSLocalizedString("Canadian Helicopters Limited", comment: "");

    let mailVC = MFMailComposeViewController()
    mailVC.mailComposeDelegate = self
    mailVC.setToRecipients(["manifests@canadianhelicopters.com"])
    mailVC.setSubject(NSLocalizedString("Manifest from \(pilotsTextField.text) for \(acRegTextField.text)", comment: "email"))
    mailVC.setMessageBody(("\(emailtext)"), isHTML: true)

    self.presentViewController(mailVC, animated:true, completion:nil)
}

However, everything found in the loop does not populate the email form...

any ideas ???


Solution

  • func sendemail() {
        let formatter = NSDateFormatter()
        formatter.dateStyle = .MediumStyle
        formatter.timeStyle = .FullStyle
        let dateString = formatter.stringFromDate(datePicker.date)
    
        var emailtext = NSLocalizedString("Pilot name : ", comment: "");
        emailtext += String(pilotsTextField.text)
        emailtext += "<br />";
        emailtext += NSLocalizedString("Aicraft : C-", comment: "");
        emailtext += String(acRegTextField.text)
        emailtext += "<br />";
        emailtext += "<br />";
        emailtext += NSLocalizedString("Passengers :", comment: "");
        emailtext += "<br />";
        for (var i=0 ; i < passengers.count; i++) {
                       let passenger = passengers[i]
            emailtext += "Name: \(passenger.paxName)"
            emailtext += "<br />";
            emailtext += "Name: \(passenger.paxWeight)"
            emailtext += "<br />";
            emailtext += "Name: \(passenger.paxEmergencyName)"
            emailtext += "<br />";
            emailtext += "Name: \(passenger.paxEmergencyPhone)"
            emailtext += "<br />";
            emailtext += "Name: \(passenger.paxDestinationComments)"
            emailtext += "<br />";
            emailtext += "<br />";
        }
        emailtext += "<br />";
        emailtext += "Date and Departure time : ";
        emailtext += dateString;
        emailtext += "<br />";
        emailtext += NSLocalizedString("Canadian Helicopters Limited", comment: "");
    
        let mailVC = MFMailComposeViewController()
        mailVC.mailComposeDelegate = self
        mailVC.setToRecipients(["manifests@canadianhelicopters.com"])
        mailVC.setSubject(NSLocalizedString("Manifest from \(pilotsTextField.text) for \(acRegTextField.text)", comment: "email"))
        mailVC.setMessageBody(emailtext, isHTML: true)
    
        self.presentViewController(mailVC, animated:true, completion:nil)
    }