Answer the question
In order to leave comments, you need to log in
How to send valid html email via php to gmail?
There is a simple php code that sends an html page to all recipients in a loop
$code = '';
$message = file_get_contents($this->message_file);
$this->message = base64_encode($message);
foreach($this->to as $to){
$code .= '
$to = "'.$to.'";
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\n";
$headers .= "From: '. $this->from .' " . "\n";
$subject = "Message sent from ".$_SERVER[\'SERVER_NAME\'];
mail($to, $subject, base64_decode("'.$this->message.'"), $headers);
';
Answer the question
In order to leave comments, you need to log in
Don't reinvent the wheel. Use ready-made solutions, for example - phpmailer . Then the sending procedure will look like this:
<?php
$mail = new PHPMailer;
$mail->setFrom('[email protected]'); // Email отправителя
// Можно отправить письмо нескольким адресатам за один раз
$recipients = ['[email protected]', '[email protected]', '[email protected]'];
foreach ($recipients as $recipient) {
$mail->addAddress($recipient);
//$mail->AddBCC($recipient); // Или можно отправить скрытую копию, чтобы получатели не видели друг друга
}
$mail->Subject = 'Заголовок письма';
$mail->Body = '<b>Здесь текст письма в формате html.<b>';
$mail->isHTML(true); // Формат HTML
$mail->send();
Styles in the letter are made like this?
https://www.codecademy.com/articles/html-inline-styles
Try like this
and header
Content-Transfer-Encoding: quoted-printable
Content-type: text/html; charset=utf-8
MIME-Version: 1.0
mail($email, "=?utf-8?b?" . base64_encode("Тема письма") . "?=", quoted_printable_encode("тело письма с html"), $header);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question