그러냐

php 폼메일 소스 mail() 본문

php

php 폼메일 소스 mail()

관절분리 2017. 1. 9. 15:35
반응형

1. 간단 소스

 

출처 : https://www.mireene.com/index.php?pid=service_faq/faq_view&uid=136&c1_uid=3&page=&keyword=

 

sendmail_test.zip

 

 

2. 한메일 보내지는 소스

 

  1번소스도 되는듯?

 

  주석때문에 지져분한데 적당히 수정해서 쓰시길

 

1)


$tit = iconv('utf-8','euc-kr',$_POST["subject"]);
$tit = $_POST["subject"];
$text  = $_POST["content"];

$receiver_email = $_POST["mailadd"];  //받는 사람
$receiver  = $_POST["mailname"];

$receiver ='';
$receiver_email  = "";   //받는 사람 Emai

 $email = 'bononara@mailplug.co.kr';
 $name = iconv('utf-8','euc-kr','관리자');
 $name ='관리자';
//  $text = addslashes($text);
//  $body = nl2br($text);

  $vl = xmail('html',$receiver_email,$receiver,$email,$name,$tit,$text); 

//     $mailheaders = "Return-Path: $email\r\n";
//     $mailheaders .= "From: $name <$email>\r\n";
//
//     $mailheaders .= "Content-Type: text/html; charset=utf-8\r\n";
//     $bodytext =  stripslashes($body);
//mail($receiver_email,$tit,$bodytext,$mailheaders,"-f bonjung.co.kr");
 

// $vl = mail($receiver_email,$tit,$bodytext,$mailheaders,"-f mailplug.co.kr");
  
    if($vl==1){
  echo "ok";
    }else{
  echo "failed"; 
    }

 


 function xmail($type,$to,$to_name,$from,$from_name,$title,$message,$charset="utf-8")
 {
  global $_FILES;

  if($type!='html'){
   $message = nl2br($message);
   $contentType = "Content-Type: text/plain; charset=\"$charset\"; format=flowed";
  }else{
   $contentType = "Content-Type: text/html; charset=\"$charset\"";
  }

  $boundary = '----='.uniqid(rand(),true);

  $title = "=?$charset?B?".base64_encode($title)."?=";
  $from_name = "=?$charset?B?".base64_encode($from_name)."?=";
  $to_name = "=?$charset?B?".base64_encode($to_name)."?=";
  $recipient = sprintf("%s <%s>", $to_name, $to);

  $headers = sprintf(
   "From: %s <%s>\r\n".
   "Reply-to: <%s>\r\n".
   "Subject: %s\r\n".
   "X-Mailer: webmailer\r\n".
   "MIME-Version: 1.0\r\n".
   "Content-Type: multipart/mixed;\r\n\tboundary=\"%s\"\r\n\r\n",
   $from_name,
   $from,
   $from,
   $title,
   $boundary
  );

  $body = sprintf(
   "--%s\r\n".
   "%s\r\n".
   "Content-Transfer-Encoding: base64\r\n".
   "Content-Disposition: inline\r\n\r\n".
   "%s\r\n".
   "--%s",
   $boundary,
   $contentType,
   chunk_split(base64_encode(strip_tags($message))),
   $boundary
  );

//  $ufile = @$_FILES['attach'];
//  if( is_array($ufile) ){
//  foreach( $ufile['tmp_name'] as $key=>$val )
//  {
//   if( empty($ufile['tmp_name'][$key]) ) continue;
//
//   $ftype = $ufile['type'][$key];
//   $fname = $ufile['name'][$key];
//
//   $fp = fopen($ufile['tmp_name'][$key],"r");
//   $file = fread($fp, $ufile['size'][$key]);
//   fclose($fp);
//   @unlink($ufile['tmp_name'][$key]);
//
//   $body .= sprintf(
//   "\r\nContent-Type: %s; name=\"=?$charset?B?".base64_encode($fname)."?=\"\r\n".
//   "Content-Transfer-Encoding: base64\r\n".
//   "Content-Disposition: attachment; filename=\"=?$charset?B?".base64_encode($fname)."?=\"\r\n\r\n".
//   "%s\r\n".
//   "--%s",
//   $ftype,
//   chunk_split( base64_encode($file) ),
//   $boundary
//   );
//  }
//  }

  $body .= "--";

  return mail($recipient , $title, $body, $headers,"-f mailplug.co.kr");
 }
  

 

또는

2)

 

function xmail($type,$to,$to_name,$from,$from_name,$title,$message,$charset="utf-8")
{
 global $_FILES;

 if($type!='html'){
  $message = nl2br($message);
  $contentType = "Content-Type: text/plain; charset=\"$charset\"; format=flowed";
 }else{
  $contentType = "Content-Type: text/html; charset=\"$charset\"";
 }

 $boundary = '----='.uniqid(rand(),true);

 $title = "=?$charset?B?".base64_encode($title)."?=";
 $from_name = "=?$charset?B?".base64_encode($from_name)."?=";
 $to_name = "=?$charset?B?".base64_encode($to_name)."?=";
 $recipient = sprintf("%s <%s>", $to_name, $to);

 $headers = sprintf(
  "From: %s <%s>\r\n".
  "Reply-to: <%s>\r\n".
  "Subject: %s\r\n".
  "X-Mailer: webmailer\r\n".
  "MIME-Version: 1.0\r\n".
  "Content-Type: text/html;\r\n\tboundary=\"%s\"\r\n\r\n",
  $from_name,
  $from,
  $from,
  $title,
  $boundary
 );

return mail($recipient , $title, $message, $headers,"-f mailplug.co.kr");
}


$mail = $_POST['email'];
$sec =  $_GET['sec'];


//$tit = iconv('utf-8','euc-kr',$_POST["subject"]);
$tit = "제목";
$text = "내용";

$tmp = explode("@",$mail);

$receiver_email = $mail;  //받는 사람
$receiver  = $tmp[0];

 

$email = 'admin@mailplug.co.kr';
$name ='LS IS [발신전용]';

$vl = xmail('html',$receiver_email,$receiver,$email,$name,$tit,$text); 

if($vl==1){
 echo "1";
}else{
 echo "0"; 
}

반응형