php, mysql

첨부파일사용한 폼이메일

날씨좋군 2017. 4. 13. 13:40

<?
$my_name = "보내는이 이름";
$my_email = "보내는이 이메일";
$my_subject = "제목";
$your_name = "받는이 이름";
$your_email = "받는이 이메일";
$content = "내용";


if($my_name && $my_email) $from = "\"$my_name\" <$my_email>";
else $from = "$my_email";

$your_info = "\"$your_name\" <$your_email>";
$boundary = "----".uniqid("part"); //식별자

$from2 .= "Return-Path: $from\r\n";
$from2 .= "From: $from\r\n";
$from2 .= "MIME-Version: 1.0\r\n";
$from2 .= "Content-Type: Multipart/mixed; boundary = \"$boundary\"";

$my_content .= "This is a multi-part message in MIME format.\r\n\r\n";
$my_content .= "--$boundary\r\n";
$my_content .= "Content-Type: text/html; charset=\"ks_c_5601-1987\"\r\n";
$my_content .= "Content-Transfer-Encoding: base64\r\n\r\n";
$my_content .= base64_encode($content)."\r\n\r\n";


//첨부파일 - input name = upload
if($upload) {
 $filename = basename($upload_name);
 $fp = fopen($upload, "r");
 $file = fread($fp, $upload_size);
 fclose($fp);

 // 파일첨부파트
 $my_content .= "--$boundary\r\n";
 $my_content.= "Content-Type: ".$upload_type."; name=\"".$filename."\"\r\n";
 $my_content .= "Content-Transfer-Encoding: base64\r\n";
 $my_content .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
 $my_content .= base64_encode($file)."\r\n\r\n";
}


$from = "From:$from\nContent-Type:text/html";
mail($your_info, $my_subject , $my_content , $from2);
?>