Reputation: 71
I have text Fields that populate into the body of an email. Question - How can i make the first and last name show in bold (within the email that is being sent) ?
This is my code for the email
// Send Email ----------------------------
@IBAction func SendEmail(_ sender: UIButton) {
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.setPreferredSendingEmailAddress(EmailFrom.text ?? "")
mail.mailComposeDelegate = self
mail.setToRecipients([DefaultEmail.text ?? ""])
mail.setSubject(DefaultSubject.text ?? "")
mail.setMessageBody("\(String(describing: DateTextField.text ?? "nil"))</br></br>\n\(String(describing: FirstName.text ?? "nil"))\n\(String(describing: LastName.text ?? "nil"))</br></br>\n\(String(describing: Street.text ?? "nil"))</br>\n\(String(describing: Area.text ?? "nil"))\n\(String(describing: PostCode.text ?? "nil"))</br></br>\nPhone: \(String(describing: Phone.text ?? "nil"))</br>\nEmail: \(String(describing: Email.text ?? "nil"))</br></br>\nReference: \(String(describing: Reference.text ?? "nil"))</br>\nOther Details: \(String(describing: OtherDetailsField.text ?? "nil")) ", isHTML: true)
present(mail, animated: true)
} else {
print("Application is not able to send an email")
}
}
//MARK: MFMail Compose ViewController Delegate method
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
// Dismiss the mail compose view controller.
controller.dismiss(animated: true, completion: nil)
}
Upvotes: 3
Views: 4693
Reputation: 71
This the code i had
mail.setMessageBody("\(String(describing: FirstName.text ?? "nil"))\n\(String(describing: LastName.text ?? "nil"))
This the modified code
mail.setMessageBody("\<strong>(String(describing: FirstName.text ?? "nil"))\n\(String(describing: LastName.text ?? "nil"))</strong>
Upvotes: 2
Reputation: 8979
use the <strong>
or <b>
tag in your mail content. wrap the text inside the tag, whatever you want to show bold. but you should have Content-Type: text/html
in your mail header, otherwise, the email will not show up bold text and consider it as plaintext. when you set the content type of email to text/html
you will be able to use Html tags in mail body and they going to be rendered.
Upvotes: 3