Я пытаюсь отправить электронное письмо с дополнительной строкой.Мне удалось найти связанную ссылку в StackOverflow: Добавление дополнительной строки в тело сообщения (swift) .Мне нужна помощь, чтобы добавить дополнительную строку с набранным пользователем текстовым сообщением после номера телефона.
Пример:
Имя
Электронная почта
Номер телефона
Сообщение
Вотмой код:
@IBOutlet var nameField: UITextField!
@IBOutlet var emailAddressfield: UITextField!
@IBOutlet var phoneNumberfield: UITextField!
@IBOutlet var subjectfield: UITextField!
@IBOutlet weak var requestfield: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Send(sender: Any) {
var SubjectText = "Prayer Request: "
SubjectText += subjectfield.text!
var _: [UITextField] = [nameField, phoneNumberfield, emailAddressfield]
let toRecipients = ["st.johnamechurch@att.net"]
let MessageBody = requestfield.text!
let mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(SubjectText)
mc.setMessageBody(MessageBody, isHTML: false)
mc.setToRecipients(toRecipients)
self.present(mc, animated: true, completion: nil)
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
switch result.rawValue {
case MFMailComposeResult.cancelled.rawValue:
print("Mail Cancelled")
case MFMailComposeResult.saved.rawValue:
print("sMail Saved")
case MFMailComposeResult.sent.rawValue:
print("Mail Sent")
case MFMailComposeResult.failed.rawValue:
print("Mail Failed: %@", [error?.localizedDescription])
default:
break
}
controller.dismiss(animated: true, completion: nil)
}
func dismissKeyboard(_ sender: AnyObject) {
self.resignFirstResponder()
}