简体   繁体   中英

Send HTML mail not as text

I'm getting mad with this. My goal is to send a mail that contains HTML. I have read tons of tutorials and i want to send a HTML like:

<html>
     <head>
     </head>
     <body>
           hola
      </body> 
</html>

but if i paste it in mail the result is the code as text, can anyone help me?

            $from = $systemAdmin;
        $emailTo=$email;
           $subject="New";
       $body="<html>
         <head>
         </head>
             <body>
               hola
              </body> 
          </html>";
         //to call function for mail()
         if(sendMail($emailTo,$subject,$body,$from))
         {
       return 'fail';
         }
         else
           {
      return 'success';
          }
        function sendMail($sentTo,$subject,$message,$from) // send email function
          {
          $headers  = "MIME-Version: 1.0\r\n";
          $headers .= "Content-type: text/html; charset=utf-8\r\n";
          $headers .= "From: $from\r\n";
          $headers .= "Bcc: rahul@gmail.com\r\n";
          $headers .= "Bcc: ravi@gmail.com\r\n";

       if(is_array($sentTo))
        {
          foreach($sentTo as $email){ //to add multiple mail in 'To'
        mail($email, $subject, $message, $headers);
     }
        }
        else
        {
      mail($sentTo, $subject, $message, $headers);
        }
         }

I'm assuming you are unfamiliar with PHP or another coding language and just want a quick way to slap some html into an email.

Quickest way is to open your html in a browser, then ctrl+a highlighting everything in the browser window, then copy and paste it into the body of your email. The rendered html will then remain rendered. Just make sure any images you link to are absolute (hosted online, starting with http:// , and not on your computer), otherwise your email recipient will not see them.

Keep in mind, this is a quick hack technique. If you are going to send emails to groups of people frequently, you should use an email service provider like Campaign Monitor, Mailchimp or Constant Contact.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM