将文本字段的内容作为电子邮件发送
Sending contents of a text field as an email
我希望视图控制器只包含一个文本字段和一个发送按钮。有没有办法让按钮将文本字段的内容发送到预设的电子邮件地址?或者是唯一的电子邮件功能 MFMailComposeViewController
?
您只能通过 MFMailComposeViewController
发送邮件,但您可以像下面的示例一样传递文本字段中的值。
将此代码放入您的按钮操作中:
let toRecipients = ["mail@mail.com"]
let subject = "My Subject"
let body = textField.text // Your text fields text
mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(toRecipients)
mail.setSubject(subject)
mail.setMessageBody(body, isHTML: false)
presentViewController(mail, animated: true, completion: nil)
我希望视图控制器只包含一个文本字段和一个发送按钮。有没有办法让按钮将文本字段的内容发送到预设的电子邮件地址?或者是唯一的电子邮件功能 MFMailComposeViewController
?
您只能通过 MFMailComposeViewController
发送邮件,但您可以像下面的示例一样传递文本字段中的值。
将此代码放入您的按钮操作中:
let toRecipients = ["mail@mail.com"]
let subject = "My Subject"
let body = textField.text // Your text fields text
mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(toRecipients)
mail.setSubject(subject)
mail.setMessageBody(body, isHTML: false)
presentViewController(mail, animated: true, completion: nil)