Good all the time of the day gentlemen

// функция отправки, с выводом ошибок function smtp_mail($user_smtp, $pass_smtp, $to, $subject, $message, $headers = ''){ $recipients = explode(',', $to); $smtp_host = 'ssl://smtp.googlemail.com'; $smtp_port = 465; if (!($socket = fsockopen($smtp_host, $smtp_port, $errno, $errstr, 15))) echo "Could not connect to smtp host '$smtp_host' ($errno) ($errstr)", __FILE__, __LINE__; server_parse($socket, '220'); fwrite($socket, 'EHLO '.$smtp_host."\r\n"); server_parse($socket, '250'); fwrite($socket, 'AUTH LOGIN'."\r\n"); server_parse($socket, '334'); fwrite($socket, base64_encode($user_smtp)."\r\n"); server_parse($socket, '334'); fwrite($socket, base64_encode($pass_smtp)."\r\n"); server_parse($socket, '235'); fwrite($socket, 'MAIL FROM: <example@gmail.com>'."\r\n"); server_parse($socket, '250'); foreach ($recipients as $email){ fwrite($socket, 'RCPT TO: <'.$email.'>'."\r\n"); server_parse($socket, '250'); } fwrite($socket, 'DATA'."\r\n"); server_parse($socket, '354'); fwrite($socket, 'Subject: '.$subject."\r\n".'To: <'.implode('>, <', $recipients).'>'."\r\n".$headers."\r\n\r\n".$message."\r\n"); fwrite($socket, '.'."\r\n"); server_parse($socket, '250'); fwrite($socket, 'QUIT'."\r\n"); fclose($socket); } // вызываем функцию if(smtp_mail('email@site.ru', 'pass', 'email2@site.ru', 'head', '<div style="">text</div>')) {echo "Mail sent";} else {echo "Some error occured";} 

The function works. I give her 5 parameters: E-mail, password from him (to whom the soap that distributes letters is issued), inner box, header, letter text

I have the text of the letter

 <div style="">text</div> 

Here such construction together with html tags also reaches. those. as text. Tell me what to add what would be the html letter ... and the letters were, well, because write the hunt is not only 'hello world', please tell me how to specify the windows-1251 encoding?

    2 answers 2

    Sample Fields:

     Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: base64 
    • OK. If it is not a secret, enter it in the function after: $ smtp_host? - sergey

    I would take an html-letter and see how it works) In the service headers of your letter, the content-type: text / plain is specified, therefore it is displayed as text. You need to set the text / html value in this field.

    • Yes it is. In the same function mail () quite quickly you can find where to write text / html, and the encoding. When smtp sending I can not find where and how to register the same type of letter and the same encoding. Dear, no one will tell how to type the letter? - sergey