简体   繁体   English

使用php发送HTML电子邮件不起作用

[英]sending html email using php not working


I am trying to sending an html email by using the php mail function. 我正在尝试使用php邮件功能发送html电子邮件。 Below is the code that i am using. 下面是我正在使用的代码。

public function sendActivationMail($activationCode="",$receiverEmail=""){
    $subject="Registration Confirmation";
    $body="<html><body>";
    $body.="<p>Thank you for registering with us. Please Activate your account by clicking the activation link ";
    $body.="<a href=".$this->url()->fromRoute('Login/default',array('controller'=>'Index','action'=>'activation','id'=>'abc121')).">Activate</a></p>";
    $body.="</body></html>";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
    $headers .= 'From: abc@gmail.com'."\r\n".'Reply-To: abc@gmail.com'."\r\n" .'X-Mailer: PHP/' . phpversion();
    $status=mail($receiverEmail,$subject,$body,$headers);
    if($status){
        return true;
    }else{
        echo "Error in sending mail";
        exit();
    }

}

But when i checked email then html tags appears as a text i don't know why? 但是,当我检查电子邮件时,html标记显示为文本,我不知道为什么?

You need to use 您需要使用

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

*-Type in CamelCase * -CamelCase中的类型

Try this.. 尝试这个..

This is work fr me 这是我的工作

Add header for html mail " $headers .= "Content-type: text/html\\r\\n"; " 为html邮件添加标题“ $headers .= "Content-type: text/html\\r\\n";

and send cc,bcc " 并发送cc,bcc“

$headers .= "Cc: [email]maa@p-i-s.cXom[/email]"; 
        $headers .= "Bcc: [email]email@maaking.cXom[/email]";

"

<?php
    //change this to your email. 
    $to = "xxxxxxxxx@gmail.com"; 
    $from = "xxxxxxx@gmail.com"; 
    $subject = "Hello! This is HTML email"; 

    //begin of HTML message 
    $message = '
<html> 
  <body bgcolor="#DCEEFC"> 
    <center> 
        <b>Looool!!! I am reciving HTML email......</b> <br> 
        <font color="red">Thanks Mohammed!</font> <br> 
        <a href="http://www.maaking.com/">* maaking.com</a> 
    </center> 
      <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine 
  </body> 
</html>'; 


    $headers  = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n"; 

    //options to send to cc+bcc 
    //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]"; 
    //$headers .= "Bcc: [email]email@maaking.cXom[/email]"; 

    // now lets send the email. 
    mail($to, $subject, $message, $headers); 

    echo "Message has been sent....!"; 
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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