4

I've the following PHP code for sending e-mails with PHP mail() as HTML:

<?php
    $to = "test@example.com";

    $subject = "This is the subject";

    $headers = "From: Me<test@exapmle.com>\r\n";
    $headers .= "Return-Path: test@exapmle.com\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=utf-8\r\n";
    $headers .= "X-Priority: 1\r\n";

    $message = "This is my <b>message</b>!";

    mail($to,$subject,$message,$headers);
?>

But I want to support plain text and HTML. HTML for things like bold font and plain text to show This is my message! in non-html supporting email clients instead of This is my <b>message</b>!.

How can I do this?

I read about boundary. Is that what I'm looking for? But if so, how to use it? I don't understand it.

David
  • 2,898
  • 3
  • 21
  • 57

1 Answers1

3

I would strongly suggest you to use existing library like PHPMailer (https://github.com/PHPMailer/PHPMailer), which could do everything you need and even more.

$mail = new PHPMailer;
$mail->isHTML(true);
$mail->Body = '<b>Html body</b> here.';
$mail->AltBody = 'Normal text here.';
Zapo
  • 211
  • 1
  • 6