Question

When sending an email I want to show the hyperlink value not the whole href. This is my code

if ($model->update(array('status'))) 
{
    $body.="Your account has now been verified. Please, login and spiff up your profile and take a look at our ,";
    $body.="<a href='https://contactcenters.com/page/58/?Advertisewithus'>sponsorship program</a>";
    $body.="to start building your business!";
    $email=$model->email;
    mail($email,$subject,$body,$headers);
    //----------------------------------------------------------//
    $this->redirect($model->user_id);
}

I want to send sponsored program not the whole href in the mail body. But whenever I send an email using this it prints <a href='https://contactcenters.com/page/58/?Advertisewithus'>sponsorship program</a>"; instead of Sposorship Program

I have tried to add double quotes inside single quotes but it didn't work.

Was it helpful?

Solution

You need to add to headers:

$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

if you haven't done it yet.

Also you have to make sure your e-mail client is properly set. For example in Mozilla Thunderbird you may set it to display only TXT and then it may perform some changes to the content. Otherwise you may send email correctly but you will result you don't expect

OTHER TIPS

Based on http://php.net/manual/en/function.mail.php

You need to inform mail engine, that you are sending something more complicated then just text

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

You are sending the mail as plain text, so html would not be recognized. Add these to the $headers:

$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

See http://www.php.net/manual/en/function.mail.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top