как отправить html-почту с помощью почты PEAR

Я использую почтовую систему PEAR для отправки аутентифицированных почтовых сообщений. Мне нужно отправить HTML-письма с alinks.It работает нормально, прежде чем я начну использовать почту PEAR. Теперь я не могу отправлять письма HTML.

mail выглядит так:

$body = <<<EOD Hiya $username You might be interested in the current 'haves' and 'wants' on example.com Latest Haves <a href="http://www.exmaple.com/product/have/64/Titan+Fast+Track+SunGlass">Titan Fast Track SunGlass</a> EOD; 

тег появляется, как есть в почте. Любая идея, как решить эту проблему?

Related of "как отправить html-почту с помощью почты PEAR"

Если вы следуете этому примеру, нет причин, по которым он не должен работать:

 <? include('Mail.php'); include('Mail/mime.php'); // Constructing the email $sender = "Leigh <leigh@no_spam.net>"; // Your name and email address $recipient = "Leigh <leigh@no_spam.net>"; // The Recipients name and email address $subject = "Test Email"; // Subject for the email $text = 'This is a text message.'; // Text version of the email $html = '<html><body><p>This is a html message</p></body></html>'; // HTML version of the email $crlf = "\n"; $headers = array( 'From' => $sender, 'Return-Path' => $sender, 'Subject' => $subject ); // Creating the Mime message $mime = new Mail_mime($crlf); // Setting the body of the email $mime->setTXTBody($text); $mime->setHTMLBody($html); $body = $mime->get(); $headers = $mime->headers($headers); // Sending the email $mail =& Mail::factory('mail'); $mail->send($recipient, $headers, $body); ?> в <? include('Mail.php'); include('Mail/mime.php'); // Constructing the email $sender = "Leigh <leigh@no_spam.net>"; // Your name and email address $recipient = "Leigh <leigh@no_spam.net>"; // The Recipients name and email address $subject = "Test Email"; // Subject for the email $text = 'This is a text message.'; // Text version of the email $html = '<html><body><p>This is a html message</p></body></html>'; // HTML version of the email $crlf = "\n"; $headers = array( 'From' => $sender, 'Return-Path' => $sender, 'Subject' => $subject ); // Creating the Mime message $mime = new Mail_mime($crlf); // Setting the body of the email $mime->setTXTBody($text); $mime->setHTMLBody($html); $body = $mime->get(); $headers = $mime->headers($headers); // Sending the email $mail =& Mail::factory('mail'); $mail->send($recipient, $headers, $body); ?> в <? include('Mail.php'); include('Mail/mime.php'); // Constructing the email $sender = "Leigh <leigh@no_spam.net>"; // Your name and email address $recipient = "Leigh <leigh@no_spam.net>"; // The Recipients name and email address $subject = "Test Email"; // Subject for the email $text = 'This is a text message.'; // Text version of the email $html = '<html><body><p>This is a html message</p></body></html>'; // HTML version of the email $crlf = "\n"; $headers = array( 'From' => $sender, 'Return-Path' => $sender, 'Subject' => $subject ); // Creating the Mime message $mime = new Mail_mime($crlf); // Setting the body of the email $mime->setTXTBody($text); $mime->setHTMLBody($html); $body = $mime->get(); $headers = $mime->headers($headers); // Sending the email $mail =& Mail::factory('mail'); $mail->send($recipient, $headers, $body); ?> 

ПРИМЕЧАНИЕ. Для того, чтобы приведенный выше пример работал, нужен пакет Mear Pear Mail в дополнение к Pear Mail. Вы можете получить пакет https://pear.php.net/package/Mail_Mime/download .

Как выглядят ваши заголовки? Вот мои:

 $headers = array( 'To' => $recipients, 'From' => $adminEmail, 'Subject' => $subject, 'MIME-Version' => 1, 'Content-type' => 'text/html;charset=iso-8859-1' ); 

Обратите внимание, что пример, отправленный karim79, имеет параметр заголовка, который может вызвать у вас много горя: «Return-Path» – когда я включил этот параметр, как пример, он не позволил мне добавить имя от имени, работал только адрес электронной почты отправителя.

В частности (когда я добавил параметр debug, чтобы увидеть, что происходит), добавлены дополнительные угловые скобки вокруг имени from, поэтому он попытался отправить это на SMTP-сервер:

От: <от имени <имя@domain.com >> или
From: <"from name" <name@domain.com >>, когда я пытался использовать кавычки.
Это заставило соединение smtp выйти с ошибкой недействительного адреса.

Также при использовании класса mime_mail вам нужно указать параметр «To:» в заголовках или он будет отправлен на нераскрытые адреса при его получении. Поэтому замените параметр Return-Path параметром To, и он будет работать.