Hi! All,
I am trying to send email through mail function, email is sending successfully but problem is HTML email is encoded by CHtml::encode() because recipient seeing just HTML code in email.
See my uses:
$message = "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
<head><title>New Contact by {$model->name}</title></head>
<body>
<h1>New Contact by {$model->name}</h1>
<p>Recommended information provided by subscriber as below:</p><p> </p>
<table width=\"400\" border=\"1\" cellpadding=\"6\" cellspacing=\"0\" style=\"border-collapse:collapse;\">
<tbody>
<tr><td bgColor=\"#EEEEEE\" align=\"right\">Name: </td><td>{$model->name}</td></tr>
<tr><td bgColor=\"#EEEEEE\" align=\"right\">Email: </td><td>{$model->email}</td></tr>
<tr><td bgColor=\"#EEEEEE\" align=\"right\">Phone: </td><td>{$model->phone}</td></tr>
<tr><td bgColor=\"#EEEEEE\" align=\"right\">Company: </td><td>{$model->company}</td></tr>
<tr><td bgColor=\"#EEEEEE\" align=\"right\">Designation: </td><td>{$model->designationTypes[$model->designation_type]}</td></tr>
<tr><td bgColor=\"#EEEEEE\" align=\"right\">Subject: </td><td>{$model->subject}</td></tr>
<tr><td bgColor=\"#EEEEEE\" align=\"right\">Message: </td><td>{$model->message}</td></tr>
</tbody>
</table>
</body></html>";
$subject = "New Contact by " . $model->name;
$headers = "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/html; charset=utf-8" . PHP_EOL;
$headers .= "From: " . Yii::app()->params['adminEmail'] . PHP_EOL . "Reply-To: " . $model->email . PHP_EOL;
mail(Yii::app()->params['contactPost'], $subject, $message, $headers);
Yii::app()->user->setFlash('Contact', 'sent');
$this->refresh();
Received Email sample by recipient:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>New Contact by VINAY Kr. SHARMA</title></head>
<body>
<h1>New Contact by VINAY Kr. SHARMA</h1>
<p>Recommended information provided by subscriber as below:</p><p> </p>
<table width="400" border="1" cellpadding="6" cellspacing="0" style="border-collapse:collapse;">
<tbody>
<tr><td bgColor="#EEEEEE" align="right">Name: </td><td>VINAY Kr. SHARMA</td></tr>
<tr><td bgColor="#EEEEEE" align="right">Email: </td><td>me@mydomain.com</td></tr>
<tr><td bgColor="#EEEEEE" align="right">Phone: </td><td>9911111111</td></tr>
<tr><td bgColor="#EEEEEE" align="right">Company: </td><td>My Company Name</td></tr>
<tr><td bgColor="#EEEEEE" align="right">Designation: </td><td>Developer</td></tr>
<tr><td bgColor="#EEEEEE" align="right">Subject: </td><td>Wohooo</td></tr>
<tr><td bgColor="#EEEEEE" align="right">Message: </td><td>Trying to send email through Yii PHP mail() function</td></tr>
</tbody>
</table>
</body>
</html>
Please help me to resolve this issue:
Thanks
VKS