I wish to send an email using HTML if allowed by the client, else text. Something like the following:
$mail = new PHPMailer();
$htmlMessage="Hello John,<br /><br />How are you?";
$textMessage="Hello John,
How are you?";
$mail->Body = $htmlMessage;
$mail->AltBody = $textMessage;
I don't wish to write out the whole message for both, however, but create one version, and automatically convert it to the second.
Given this exact message, should I just create $textMessage
, and then use nl2br()
to add the HTML line breaks?
What if my HTML message was a bit more complicated and included bold text, a list, etc? I am okay with the Text message being somewhat ugly, but don't want a bunch of HTML tags in the message. What are my options for this scenario?