폼메일 파일첨부 기능 추가 좀 도와주세요ㅠ
본문
안녕하세요.
예전에 트리플님이 올려주신 폼메일(그누보드 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);
}
------------------------------------------------------------------------------------------------------
아래는 업로드한 파일 그대로 (이름과 확장자) 메일 전송하려고 수정한 코드인데요. 이렇게 하면 아래처럼 경고 문구가 나오면서 메일은 발송되지만 파일은 전송되질 않습니다. 하위 디렉토리 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);
}