폼메일 파일첨부 기능 추가 좀 도와주세요ㅠ

폼메일 파일첨부 기능 추가 좀 도와주세요ㅠ

QA

폼메일 파일첨부 기능 추가 좀 도와주세요ㅠ

본문

안녕하세요.

예전에 트리플님이 올려주신 폼메일(그누보드 5.3) https://sir.kr/g5_skin/20940?page=2 에

파일 첨부기능을 넣기위해서

contact.php 파일을 아래와 같이 수정해서 테스트하면 파일 전송은 되긴 하는데

tempnam 함수 때문에 파일 이름이 아래처럼 옵니다. 일단 파일이 오는지만 테스트 한거구요. 

(코드에 관련된 부분만 굵은 글씨체로 바꾸어놓았습니다.)

--------------------------------------------------------------------------------------------------

        // SMTP ENABLED [isset = for old versions]

        if(!isset($config['use_smtp']) || isset($config['use_smtp']) && $config['use_smtp'] === true) {

 

            $uploadfile = tempnam(sys_get_temp_dir(), basename($_FILES['userfile']['name']));

            move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);

 

            require('phpmailer/5.1/class.phpmailer.php');

            require('phpmailer/5.1/class.smtp.php');

 

            $m = new PHPMailer();

            $m->IsSMTP();

            $m->SMTPDebug   = false;                    // enables SMTP debug information (for testing) [default: 2]

            $m->SMTPAuth    = true;                     // enable SMTP authentication

            $m->Host        = $config['smtp_host'];     // sets the SMTP server

            $m->Port        = $config['smtp_port'];     // set the SMTP port for the GMAIL server

            $m->Username    = $config['smtp_user'];     // SMTP account username

            $m->Password    = $config['smtp_pass'];     // SMTP account password

            $m->SingleTo    = true;

            $m->CharSet     = "UTF-8";

            $m->Subject     = $array['contact_subject'];

            $m->AltBody     = 'To view the message, please use an HTML compatible email viewer!';

 

            $m->addAttachment($uploadfile, $_FILES['userfile']['name']);

 

            $m->AddAddress($config['send_to'], 'Contact Form');

            $m->AddReplyTo($array['contact_mail'], $array['contact_name']);

            $m->SetFrom($config['smtp_user'], 'Contact Form');

            $m->MsgHTML($mail_body);

 

            if($config['smtp_ssl'] === true)

                $m->SMTPSecure = 'ssl';                 // sets the prefix to the server

 

            // @SEND MAIL

            if($m->Send()) {

                die('_sent_ok_');

            } else {

                die($m->ErrorInfo);

            }

 

            unset($array, $m);

 

        }

2039568765_1574145971.121.png

------------------------------------------------------------------------------------------------------

 

아래는 업로드한 파일 그대로 (이름과 확장자) 메일 전송하려고 수정한 코드인데요. 이렇게 하면 아래처럼 경고 문구가 나오면서 메일은 발송되지만 파일은 전송되질 않습니다. 하위 디렉토리 temp 의 폴더 및 파일 권한은 777로 변경했습니다.

어떻게 하면 파일 전송이 될는지요?? 고민을 한참해도 무엇때문인지 잘 모르겠네요....

좀 도와주세요

 

        // SMTP ENABLED [isset = for old versions]

        if(!isset($config['use_smtp']) || isset($config['use_smtp']) && $config['use_smtp'] === true) {

 

            $uploadfile = 'temp/' . basename($_FILES['userfile']['name']);

            move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);

 

            require('phpmailer/5.1/class.phpmailer.php');

            require('phpmailer/5.1/class.smtp.php');

 

            $m = new PHPMailer();

            $m->IsSMTP();

            $m->SMTPDebug   = false;                    // enables SMTP debug information (for testing) [default: 2]

            $m->SMTPAuth    = true;                     // enable SMTP authentication

            $m->Host        = $config['smtp_host'];     // sets the SMTP server

            $m->Port        = $config['smtp_port'];     // set the SMTP port for the GMAIL server

            $m->Username    = $config['smtp_user'];     // SMTP account username

            $m->Password    = $config['smtp_pass'];     // SMTP account password

            $m->SingleTo    = true;

            $m->CharSet     = "UTF-8";

            $m->Subject     = $array['contact_subject'];

            $m->AltBody     = 'To view the message, please use an HTML compatible email viewer!';

 

            $m->addAttachment($uploadfile, $_FILES['userfile']['name']);

 

            $m->AddAddress($config['send_to'], 'Contact Form');

            $m->AddReplyTo($array['contact_mail'], $array['contact_name']);

            $m->SetFrom($config['smtp_user'], 'Contact Form');

            $m->MsgHTML($mail_body);

 

            if($config['smtp_ssl'] === true)

                $m->SMTPSecure = 'ssl';                 // sets the prefix to the server

 

            // @SEND MAIL

            if($m->Send()) {

                die('_sent_ok_');

            } else {

                die($m->ErrorInfo);

            }

 

            unset($array, $m);

 

        }

 

 

2039568765_1574146160.2622.png

 

 

이 질문에 댓글 쓰기 :

답변 1

답변을 작성하시기 전에 로그인 해주세요.
전체 123,629 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT