this is how i am sending an email using the Mail() class from opencart:
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
//$mail->setTo($this->config->get('config_email'));
//$mail->setFrom($this->request->post['email']);
$mail->setTo('[email protected]');
$mail->setFrom('[email protected]');
$mail->setSender($this->request->post['name']);
$mail->setSubject(html_entity_decode('La reserva de tu alquiler ha sido correcta', ENT_QUOTES, 'UTF-8'));
$mailText = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div class="confirmacion">
<h1>Su reseva se ha realizado correctamente</h1>
<p> El pago del alquiler se hará en su totalidad al momento de recoger la bicicleta en Euros, o tarjeta de crédito. También se deberán aportar 50€ en forma de depósito reembolsable, el cual será devuelto al verificar que la bicicleta se devuelve limpia y en las mismas condiciones en las que se ha recodigo. Cualquier daño o perdida de la bicicleta de cualquiera de sus partes durante el periodo de alquiler son responsabilidad del cliente y deberá ser pagado acordemente.</p>
</div>
</body>
</html>';
$mail->setText($mailText);
$mail->send();
The problem is that instead of seeing the HTML result, i see the HTML code in the email,
what am I doing wrong?
setText()
is for text only content. Use setHtml()
for HTML content:
$mail->setHtml($mailText);
You can set both, but obviously don't pass HTML to setText()
. If you set both, the recipients email client will decide which to display, based on their preferences.
Snippet from the Mail class:
public function setText($text) {
$this->text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
}
public function setHtml($html) {
$this->html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With