PEARメールを使用してHTMLメールを送信する方法 質問する

PEARメールを使用してHTMLメールを送信する方法 質問する

認証されたメールを送信するために PEAR メール システムを使用しています。リンクを含む HTML メールを送信する必要があります。PEAR メールの使用を開始する前は正常に動作していましたが、現在は HTML メールを送信できません。

メール本文は次のようになります:

$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;

タグがメールにそのまま表示されます。これを解決する方法をご存知ですか? 助けてください。

ベストアンサー1

この例に従えば、動作しない理由はありません。

<?php
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>HTML message</p></body></html>';// HTML version of the email
$crlf = "\r\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);
?>

注記:上記の例を動作させるには、Pear Mailパッケージに加えてPear Mail Mimeパッケージが必要です。パッケージはここから入手できます。https://pear.php.net/package/Mail_Mime/ダウンロード

おすすめ記事