2016-08-31 7 views
0
<?php 
include 'include/function.php'; 

//$random_hash = md5(time()); 
$User=new User(); 
session_start(); 

$id=$_POST['id']; 
    //$date=$_POST['date']; 
    $expected_date=$_POST["expected_date"]; 

    $comname=$_POST['comname']; 
    $type=$_POST["type"]; 
    $name=$_POST["name"]; 
    $mime=$_POST["mime"]; 
    $size=$_POST["size"]; 
    $file1=$_POST["path"]; 

    //$comname=$_POST["comname"]; 
    $remark=$_POST["remark"]; 

    $other_detail=$_POST['other_detail']; 
    $remark=$_POST["remark"]; 
    //$last_change_time=$row['last_change_time']; 
    $email1=$_POST['email1']; 
    $email2=$_POST['email2']; 
    $email3=$_POST['email3']; 
    $email4=$_POST['email4']; 



    $email5=$_POST['email5']; 
    $email6=$_POST['email6']; 
    $username=$_SESSION["username"]; 
    //$username=$row['username']; 



$sql=mysql_query("update depository set expected_date='$expected_date',comname='$comname',last_change_username='$username',type='$type',name='$name',mime='$mime',size='$size',path='$file1',other_detail='$other_detail',remark='$remark',email1='$email1',email2='$email2',email3='$email3',email4='$email4',email5='$email5',email6='$email6'where id='$id'"); 






$htmlbody = " Message successfully send ok"; 


//$to .= [email protected]; 
//Recipient Email Address [email protected] 
$to = $email1. ', '; 
$to .= $email3. ', '; 
$to .= $email2. ', '; 
$to .= "[email protected]"; 
$subject = 'Depositiory Detail From Solution Infinite'; //Email Subject 

$headers = "From: [email protected]\r\nReply-To: [email protected]"; 

$random_hash = md5(date('r', time())); 

$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; 

$attachment = chunk_split(base64_encode(file_get_contents($file1))); // Set your file path here 

//define the body of the message. 

$message = "--PHP-mixed-$random_hash\r\n"."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n"; 
$message = "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n"; 

//Insert the html message. 
$message .= $htmlbody; 
$message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n"; 

//include attachment 
$message .= "--PHP-mixed-$random_hash\r\n"."Content-Type: application/pdf; name=\"$name\"\r\n"."Content-Transfer-Encoding: base64\r\n"."Content-Disposition: attachment\r\n\r\n"; 
$message .= $attachment; 
$message .= "/r/n--PHP-mixed-$random_hash--"; 

//send the email 
$mail = mail($to, $subject , $message, $headers); 

echo $mail ? "Mail sent" : "Mail failed"; 


?> 

正しく送信するよりもメールを送信すると、添付ファイルのメールよりLinuxでスクリプトを実行するとプレーンテキストで送信されます。以下に示すのフルテキストで送信Linuxのメール添付ファイルでヘッダーの問題が発生する

メール:

PHP-mixed 83d06f048e070e4cfc0684d0e98f71db  
Content-Type: application/jpg; name="tkt.jpg"  
Content-Transfer-Encoding: base64  
Content-Disposition: attachment 


/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcG  
BwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwM  
DAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAMABVYDASIA  
AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA 
+0

Linuxスタイルの改行文字: '\ r \ n 'の代わりに' \ n'を使用するか、 'PHP_EOL'定数を使用してください。 – beerwin

+0

答えとして追加しました – beerwin

答えて

1

これは、PHP定数PHP_EOLが存在するこのような状況(プラットフォーム間の互換性)のためです。新しいコメントの情報、およびコードをもう一度見に基づいて

窓が今までHTMLとしてメッセージを配信し、なぜ、私は疑問に思う:

<?php 
    .... 
    $eol = PHP_EOL; 
    $headers = "From: [email protected]".$eol."Reply-To: [email protected]"; 

    $random_hash = md5(date('r', time())); 

    $headers .= $eol."Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; 

    $attachment = chunk_split(base64_encode(file_get_contents($file1))); // Set your file path here 

    //define the body of the message. 

    $message = "--PHP-mixed-$random_hash".$eol."Content-Type: text/html; charset=\"iso-8859-1\"".$eol."Content-Transfer-Encoding: 7bit".$eol.$eol; 

    //Insert the html message. 
    $message .= $htmlbody.$eol.$eol."--PHP-mixed-$random_hash".$eol; 

    //include attachment 
    $message .= "Content-Type: application/pdf; name=\"$name\"".$eol."Content-Transfer-Encoding: base64".$eol."Content-Disposition: attachment; filename=\"".$name."\"".$eol; 
    $message .= $attachment; 
    $message .= $eol."--PHP-mixed-$random_hash--"; 

    //send the email 
    $mail = mail($to, $subject , $message, $headers); 

    echo $mail ? "Mail sent" : "Mail failed"; 


?> 

EDIT:これを行います。あなたは、あなたが最も可能性の高いあなたの問題を解決する必要があり、単純に

$message = "--PHP-alt-$random_hash".$eol."Content-type:text/html; charset=iso-8859-1".$eol."Content-Transfer-Encoding: 7bit".$eol.$eol; 

これにそれを変更する必要があり、ここで

$message = "--PHP-alt-$random_hash\r\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\r\nContent-Transfer-Encoding: 7bit\r\n\r\n" 

プレーンテキストなどのコンテンツタイプを/指定しました。私は、メインの答えに行われた

EDIT 2 チェック変更...

+0

おっと!私はパーティーに遅れているようだ。 @beerwinが言っていることをしてください。 – kennasoft

+0

添付ファイルは正しく送信されましたが、htmlコンテンツは送信されません。@beerwin、kennasoft –

+0

はいメールは添付ファイルで送信されますが、問題は$ htmlbodyコンテンツがメールで送信されていません@kennasoft –

0

使用のLinuxスタイル改行文字:\nの代わりに、\r\n、または、PHP_EOL定数を使用します。

+0

--- $ message。= $ htmlbody;の中からフォーム変数を呼び出す代わりに。 $ message。= $ comname; $メッセージに変数をハードコードします。= Like- $ message。= "Content-Transfer-Encoding:7bit \ n" $ htmlbody。 "\ n" $ comname。 "\ n";しかし、まだ問題は同じです –

0

使用PHP_EOL定数。プラットフォーム に基づいて行末を置き換えます。

注:するmysql_queryはPHP 5.5.0で廃止されました、そしてそれは、PHP 7.0.0で削除されました。 MySQLiあるいはPDO_MySQLは、この関数のused.Alternativesする必要があり、次のとおりですmysqli_query()やPDO ::クエリを()

あなたは基本的にこれを達成するための2つのオプションがあります。

1.Using PDO(のためにサポートされている任意のデータベースドライバ):MySQLの

$stmt = $pdo->prepare('SELECT * FROM employees WHERE name = :name'); 

$stmt->execute(array('name' => $name)); 

foreach ($stmt as $row) { 
    // do something with $row 
} 

2.Using MySQLiを():

$stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?'); 
$stmt->bind_param('s', $name); 

$stmt->execute(); 

$result = $stmt->get_result(); 
while ($row = $result->fetch_assoc()) { 
    // do something with $row 
} 

How can I prevent SQL-injection in PHP?

を参照してください
関連する問題