2017-07-09 7 views
-1

私のPHPのメールコードは、私がメール内のHTMLコンテンツを送信したい、このようなものですが、私はこのコード送信HTMLテンプレートは

    $to = $email;; 
        $subject = 'New Order Detail'; 
        $message = 'Hi Jane'; 
        $from = '[email protected]'; 

        // Sending email 
        if(mail($to, $subject, $message)) 
        { 
         echo 'Your mail has been sent successfully.'; 
        } 
        else 
        { 
         echo 'Unable to send email. Please try again.'; 
         $headers = 'MIME-Version: 1.0' . "\r\n"; 
         $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

         // Create email headers 
         $headers .= 'From: '.$from."\r\n". 
          'Reply-To: '.$from."\r\n" . 
          'X-Mailer: PHP/' . phpversion(); 

         // Compose a simple HTML email message 
         $message = '<html><body>'; 
         $message = '<table border="1" align="center" width="50%">'; 
         $message .= '<tr><td>Test Mail'; 
         $message .= '</td></tr>'; 
         //$message .= '<p style="color:#080;font-size:18px;">Will you marry me?</p>'; 
         $message .= '</table>'; 
         $message .= '</body></html>'; 

         // Sending email 
         if(mail($to, $subject, $message, $headers)) 
         { 
          echo 'Your mail has been sent successfully.'; 
         } else 
         { 
          echo 'Unable to send email. Please try again.'; 
         } 
        } 

私は私がメールで取得出力のこの種のHTMLテンプレートを送信することはできません。このコードでは私のミスがどこにあるか分からない... 出力

<html><body> 
<table border="1" align="center" width="50%"> 
<tr><td>Test Mail</td></tr> 
</table> 
</body></html> 

答えて

0

は、私は、電子メールを送信するためにあなたに次のスクリプトをお勧めしたいと思いif statement間違っても、いくつかのコード内のエラーとがあります。それを修正する必要があり

$headers .= "Content-type:text/ html;charset=UTF-8" . "\r\n"; 

$to = $email; 
$subject = 'New Order Detail'; 
$message_text = 'Hi Jane'; 
$from = '[email protected]'; 
$from_name = 'John'; 
$to_name = 'Smith'; 

// Sending email 
if(!empty($to) && !empty($message_text)) 
{ 
    $headers = 'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

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

    // Additional headers 
    $headers .= 'To: ' . ucwords($to_name) .' <'.$to.'>' . "\r\n"; 
    $headers .= 'From: ' . ucwords($from_name) . ' <'. $from. '>' ."\r\n"; 

    // Compose a simple HTML email message 
    $message = '<html><body>'; 
    $message = '<table border="1" align="center" width="50%">'; 
    $message .= '<tr><td>Test Mail'; 
    $message .= '</td></tr>'; 
    $message .= '<p style="color:#080;font-size:18px;">'.$message_text .'</p>'; 
    $message .= '</table>'; 
    $message .= '</body></html>'; 

    // Sending email 
    mail($to, $subject, $message, $headers); 
    echo 'Your mail has been sent successfully.'; 
}else{ 
    echo 'Unable to send email. Please try again.'; 
} 
+0

はあなたが私を伝えることができます。.. –

+0

、私はこの中でCSSコードを使用したいですコードをどのように適用すればいいですか?また、このテンプレートを5つの電子メールIDに同時に送信したいので、私は何をしなければなりませんか。 –

+0

インラインCSSプロパティを使用できます。例えば、 '

' –

0

は、適切なヘッダーの内容を追加します。

// Compose a simple HTML email message 
       $message = '<html><body>'; 
       $message = '<table border="1" align="center" width="50%">'; 
       $message .= '<tr><td>Test Mail'; 
       $message .= '</td></tr>'; 
       //$message .= '<p style="color:#080;font-size:18px;">Will you marry me?</p>'; 
       $message .= '</table>'; 
       $message .= '</body></html>'; 


$headers[] = 'MIME-Version: 1.0'; 
$headers[] = 'Content-type: text/html; charset=iso-8859-1'; 
// Additional headers 
$headers[] = 'To: abc <[email protected]>, xyz <[email protected]>'; 
$headers[] = 'From: ABC <[email protected]>'; 
$headers[] = 'Cc: [email protected]'; 
$headers[] = 'Bcc: [email protected]'; 

// Mail it 
mail($to, $subject, $message, implode("\r\n", $headers)); 
+0

OK私はこのコードを試してみましょう。..助けて幸せ –

+0

おかげ@Kunal Awasthi –

+0

歓迎、(:私のミスがどこにある@ChandreshMandaliya –

0

はUTF-8に設定あなたのキャラクターを設定します。

0

あなたが答えを持っているので、おそらくテーマにバリエーションがあります。下のコードのstyleタグ領域内にスタイルを追加できるようにするか、外部のCSSファイルへのリンクを追加する可能性がありますが、それによって問題が発生する可能性があります。

$to = $email; 
$subject = 'New Order Detail'; 
$message = 'Hi Jane'; 
$from = '[email protected]'; 

$obj=new StdClass; 
$obj->success='Your mail has been sent successfully.'; 
$obj->fail='Unable to send email. Please try again.'; 
$obj->nl="\r\n"; 


$status = @mail($to, $subject, $message); 


if($status) { 
    exit($obj->success); 
} else { 

    $headers = array(); 
    $html = array(); 

    $headers[]="MIME-Version: 1.0"; 
    $headers[]="From: {$from}"; 
    $headers[]="Reply-To: {$from}"; 
    $headers[]="X-Mailer: PHP/". phpversion(); 
    $headers[]="MIME-Version: 1.0"; 
    $headers[]="Content-type: text/html; charset=iso-8859-1"; 

    $html[]=""; 
    $html[]="<html>"; 
    $html[]="<head>"; 
    $html[]="<title>{$subject}</title>"; 
    $html[]="<style>"; 
    $html[]="p{color:red;font-size:18px;}"; 
    $html[]="table{border:1px solid black;width:50%;display:table;}"; 
    $html[]="td{text-align:center;background:yellow;color:blue;}"; 
    $html[]="</style>"; 
    $html[]="</head>"; 
    $html[]="<body>"; 
    $html[]="<table>"; 
    $html[]="<tr><td>Test Mail</td></tr>"; 
    $html[]="<tr><td><p>Will you marry me?</p></td></tr>"; 
    $html[]="</table>"; 
    $html[]="</body>"; 
    $html[]="</html>"; 


    $status = @mail($to, $subject, implode($obj->nl, $html), implode($obj->nl, $headers)); 


    exit($status ? $obj->success : $obj->fail); 
} 
関連する問題