2

私はphpを介してhtmlメールを送信するために次のコードを使用しています。私が間違っているところを以下のコードで確認してください。メールは送信できますが、html 形式では送信されません。ネット上で入手可能な非常に多くの例を試しましたが、html 形式のメールを取得できませんでした。この点で私を助けてください。

 require_once "Mail.php";
 $name="Me";
 $mail_from="info@domain.com";
 $subject=$mail_from." Emails";

 $message = " 
 <html> 
  <body bgcolor=#DDDDDD> 
   YOUR HTML EMAIL
  </body> 
 </html> 
 "; 


 $From="from: $name <$mail_from>"; 

  $headers  = "From: $From\r\n"; 
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


  $to = "Shop <info@domain.com>";

  $from = "Contact $name <info@domain.co.uk>";

  $host = "mail.exclusivehosting.net";
  $username = "info@domain.co.uk";
  $password = "(hello)";

  $headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
  $smtp = Mail::factory('smtp',
  array ('host' => $host,
  'auth' => true,
  'username' => $username,
  'password' => $password));

  $mail = $smtp->send($to, $headers, $message);


  if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
  } else {
  //echo("<p>Message successfully sent!</p>");
  echo'<table width="800" border="0" align="center" >
  <td>';
  echo "We've recived your contact information, we will get back soon!";
echo'</td>
</table>';
  }

私は次の電子メールを受け取っています

  <html> 
  <body bgcolor=#DDDDDD> 
  YOUR HTML EMAIL
  </body> 
  </html> 
4

3 に答える 3

2

次の方法を使用できます。

function sendMail($email, $subject, $message)
{
    $supportEmail = 'info@abc.com';
    $from = 'Abc';
    $msg  = $message;
    $from = str_replace(' ', '-', $from);
    $frm  = $from.' <'.$supportEmail.'>';
    preg_match("<(.*)@(.*\..*)>", $frm, $match);

    ///////////////////Headers/////////////////
    $hdr='';
    $hdr.='MIME-Version: 1.0'."\n";
    $hdr.='content-type: text/html; charset=iso-8859-1'."\n";
    $hdr.="From: {$frm}\n";
    $hdr.="Reply-To: {$frm}\n";
    $hdr.="Message-ID: <".time()."@{$match[2]}>\n";
    $hdr.='X-Mailer: PHP v'.phpversion();
    $x=@mail($email, $subject, $msg, $hdr);
    if($x==0)
    {
        $email=str_replace('@','\@', $email);
        $hdr=str_replace('@','\@',$hdr);
        $x=@mail($email, $subject, $msg, $hdr);
    }
    return $x;
}
于 2012-11-12T11:23:06.567 に答える
0

私が見る限り、スクリプトの下部にあるヘッダーを書き直しています。

コンテンツ タイプ ヘッダーを配列に追加します。

$headers = array (
    'From' => $from,
    'To' => $to,
    'Subject' => $subject,
    'Content-Type' => 'text/html; charset=iso-8859-1',
    'MIME-Version' => '1.0',

);

于 2012-11-12T11:20:27.013 に答える
0

あなたが使用することができます:

$message_new=html_entity_decode($mesage);

$message_new 変数をメール関数に渡すと、適切な出力が得られます。または、次の URL を参照してください。

http://php.net/manual/en/function.html-entity-decode.php

于 2012-11-12T11:22:42.173 に答える