2


I am trying to sending an html email by using the php mail function. 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: [email protected]'."\r\n".'Reply-To: [email protected]'."\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?

2

2 Answers 2

1

You need to use

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

*-Type in CamelCase

Sign up to request clarification or add additional context in comments.

Comments

0

Try this..

This is work fr me

Add header for html mail "$headers .= "Content-type: text/html\r\n"; "

and send cc,bcc "

$headers .= "Cc: [email][email protected][/email]"; 
        $headers .= "Bcc: [email][email protected][/email]";

"

<?php
    //change this to your email. 
    $to = "[email protected]"; 
    $from = "[email protected]"; 
    $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][email protected][/email]"; 
    //$headers .= "Bcc: [email][email protected][/email]"; 

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.