2016-09-01 10 views
0

偽のメールは、HTML形式のテキストを送信せず、代わりにきれいなHTMLコードを示すプレーンテキストを送信します。私はすでに"Content-type: text/html\r\n";を追加しましたが、それでもプレーンテキストとして送信します。PHP Pear Mail HTML形式の代わりにプレーンテキストを送信

また、特定のメールのSMTP認証を与えるには、これが迷惑メールになるためです。

誰かがこの問題を解決できますか?

<?php 
include_once('Mail.php'); 

include_once('Mail_Mime/Mail/mime.php'); 

// Settings 

$max_allowed_file_size = 20000; // size in KB 
$allowed_extensions = array(
    "jpg", 
    "png", 
    "jpeg" 
); 
$upload_folder   = './uploads/'; 
$your_email   = '[email protected]'; 
$errors    = ''; 

if (isset($_POST['submit'])) { 

    // Get the uploaded file information 

    $name_of_uploaded_file = basename($_FILES['uploaded_file']['name']); 

    // get the file extension of the file 

    $type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1); 
    $size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/20000; 

    // ------------Do Validations------------- 

    if (empty($_POST['name']) || empty($_POST['email'])) { 
     $errors .= "\n Name and Email are required fields. "; 
    } 

    if (IsInjected($visitor_email)) { 
     $errors .= "\n Bad email value!"; 
    } 

    if ($size_of_uploaded_file > $max_allowed_file_size) { 
     $errors .= "\n Size of file should be less than $max_allowed_file_size"; 
    } 

    // ------ Validate the file extension ----- 

    $allowed_ext = false; 
    for ($i = 0; $i < sizeof($allowed_extensions); $i++) { 
     if (strcasecmp($allowed_extensions[$i], $type_of_uploaded_file) == 0) { 
      $allowed_ext = true; 
     } 
    } 

    if (!$allowed_ext) { 
     $errors .= "\n The file you are trying to upload is not supported file type. " . " Only the following file types are supported: " . implode(',', $allowed_extensions); 
    } 

    // send the email 

    if (empty($errors)) { 

     // copy the temp. uploaded file to uploads folder 

     $path_of_uploaded_file = $upload_folder . $name_of_uploaded_file; 
     $tmp_path    = $_FILES["uploaded_file"]["tmp_name"]; 
     if (is_uploaded_file($tmp_path)) { 
      if (!copy($tmp_path, $path_of_uploaded_file)) { 
       $errors .= '\n error while copying the uploaded file'; 
      } 
     } 

     // send the email 

     $name   = $_POST['name']; 
     $visitor_email = $_POST['email']; 
     $user_message = $_POST['message']; 
     $to   = $your_email; 
     $subject  = "Request for an avatar"; 
     $from   = $your_email; 
     $text   = "<html> 
<body style='font-size: 120%;'> 
    <table width='100%' border='0' cellspacing='0' cellpadding='0' style='background:#e1f5fe;'> 
    <tr> 
    </tr> 
    </td> 
    <tr> 
     <td style='padding-left:5%;padding-right:5%'> 
     <p>Hi $name,</p> 
     <p style='padding-left:3%;'>messgae</p> 
     <div style='background:#b3e5fc;'> 
      <p style='padding-left:1%;'>Message : </p> 
      <p style='padding-left:2%;padding-bottom:2px;'>$message</p> 
     </div> 
     <p>Regards,</p> 
     <p style=''><b>Admin</b></p> 
     </td> 
    </tr> 
    </table><br /> 
</body> 
</html>"; 
     $headers  = "MIME-Version: 1.0" . "\r\n"; 
     $headers .= "Content-type: text/html\r\n"; 
     $message = new Mail_mime(); 
     $message->setTXTBody($text); 
     $message->addAttachment($path_of_uploaded_file); 
     $body   = $message->get(); 
     $extraheaders = array(
      "From" => $from, 
      "Subject" => $subject, 
      "Reply-To" => $visitor_email 
     ); 
     $headers  = $message->headers($extraheaders); 
     $mail   = Mail::factory("mail"); 
     $mail->send($visitor_email, $headers, $body); 

     // redirect to 'thank-you page 

     header('Location: thank-you.html'); 
    } 
} 

function IsInjected($str) 
{ 
    $injections = array(
     '(\n+)', 
     '(\r+)', 
     '(\t+)', 
     '(%0A+)', 
     '(%0D+)', 
     '(%08+)', 
     '(%09+)' 
    ); 
    $inject  = join('|', $injections); 
    $inject  = "/$inject/i"; 
    if (preg_match($inject, $str)) { 
     return true; 
    } else { 
     return false; 
    } 
} 

?> 
+0

'$ mail-> IsHTML(true)で試しました。 ' – devpro

+0

@devpro、それは彼が使用していないPHPMailerの構文です – Synchro

+1

ファイル拡張子をチェックするためのコードはひどいです - 単純な' in_array'は1行でチェックします!アップロードされたファイルに 'copy'を使わないでください。安全ではありません。 PHPのドキュメントのように、 'move_upload_file'を使用してください。私はPear Mailパッケージのドキュメントを読むべきだと思います。あなたはこれらのものをすべて手動で行う必要はありません。 – Synchro

答えて

1

あなたはプレーンテキストコンテンツとして、あなたのHTMLコンテンツを設定されています

... 
$message->setTXTBody($text); 
... 

あなたはsetHTMLBody()必要があります(あるいはその両方を...):

... 
$message->setHTMLBody($text); 
... 
+0

これで問題を解決しました.SMMの自動作成の回答を同じPHPで追加しますか? – Shamshid

+0

@Shamshidこの質問を確認してください:http://stackoverflow.com/questions/12166468/sending-html-message-through-pear-while-using-smtp-authentication-returns-an-errそれが答えることができない場合は、その特定のセクションの詳細とエラーを投稿する新しい質問をする必要があります。 – jeroen

0

あなただけ変更する必要が与えられた塊によって、ヘッダーContent-type

$headers .= "Content-Type: text/html; charset=UTF-8\r\n"; 
関連する問題