PHP Sending HTML email

PHP mail() function is used to send HTML email. HTML email message contains HTML tags like image, table, link, banners etc.

PHP Syntax :

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

$headers Parameters will be needed to send HTML message to receivers.

$headers contains details like From, Cc, Bcc, MIME-Version, Content-type etc.
Content-type should be text/html.

PHP Example : 

<html>
   
   <head>
      <title>Sending HTML email using PHP</title>
   </head>
   
   <body>
      
      <?php
         $to = "[email protected]";
         $subject = "Learn JAVA by aryatechno.";
         

         $message ="<html> <head> <title>Learn Core Java.</title></head><body>";
         $message .= "<b>This is HTML message.</b>";
         $message .= "<h1>Core Java.</h1>";
         $message .= "<p>java is object oriented language.</p>";

         $message ="</body></html>";
         
         $header = "From:[email protected] \r\n";
         $header .= "Cc:[email protected] \r\n";
         $header .= "MIME-Version: 1.0\r\n";
         $header .= "Content-type: text/html\r\n";
         
         $status = mail ($to,$subject,$message,$header);
         
         if($status == true) {
            echo "HTML Message is sent successfully..";
         }else {
            echo "HTML Message is not sent successfully..";
         }
      ?>
      
   </body>
</html>

 

Output:

HTML Message is sent successfully..

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

16641