php form 메일작업 (지메일 및 회사이메일로도 보내고싶어요.)
본문
php로 form메일 짜서 네이버이메일로 잘 오는데요.
"gmail" 및 "회사이메일"로도 보내지게 하고 싶습니다!
도움을 좀 부탁드립니다!
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$firstname = $_POST['firstname'];
$companyname = $_POST['companyname'];
//$job = $_POST['job'];
$phone = $_POST['phone'];
$email = $_POST['email'];
//$address = $_POST['address']; // 받는사람
$subject = $_POST['subject'];
$title = "[SOENERGY] 문의 내역입니다."; // 제목
$title_encode = "=?utf-8?B?".base64_encode($title)."?=\n"; //제목 인코딩
$fp;
$fsize;
$fp = fopen('mail_contents.html',"r");
$fsize = filesize('mail_contents.html');
$contents = fread($fp,$fsize); //내용
$contents = str_replace('{firstname}', $firstname, $contents);
$contents = str_replace('{companyname}', $companyname, $contents);
//$contents = str_replace('{job}', $job, $contents);
$contents = str_replace('{phone}', $phone, $contents);
$contents = str_replace('{email}', $email, $contents);
//$contents = str_replace('{address}', $address, $contents);
$contents = str_replace('{subject}', $subject, $contents);
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; //헤더인코딩
$headers .= "From: SOENERGY <root@uws7-163.cafe24.com>\r\n"; //보내는 사람
$send_mail = mail("*** 개인정보보호를 위한 이메일주소 노출방지 ***", $title_encode, $contents, $headers); //메일보내기
if($send_mail == 1){
echo "<script>
alert('completed');
window.location.href='contact.php';
</script>";
}else{
echo "<script>
alert('Failed to send mail');
window.location.href='contact.php';
</script>";
}
}
?>
답변 3
아래는 제가 사용하고 있는 내용 입니다.
저도 네이버 발신 수신 잘됩니다.
다음은 간혹 안오든가 받은메일함(가끔) 또는 스펨메일함으로 오고요.
간혹(자주) 네이버는 "네이버에서 보낸메일이 아닙니다." 라는 문구도 같이 표시되고요..
포털사 보안정책 및 화이트도메인 등등 여러 사유로 메일이 차단될 수 있습니다.
네이버 사용시 메일이 잘 온다는건 이상이 없다고 보시면 될꺼 같습니다.
메일 잡다 1달 고생하고...
돈들여 메일서버 운영하거나
SMS 동시 운영하는 거로 안내 하고 있습니다.
수고하세요... ^^;;
---
<?php
if (!defined('_GNUBOARD_')) exit;
include_once(COSE_PLUGIN_PATH.'/PHPMailer/PHPMailerAutoload.php');
// 메일 보내기 (파일 여러개 첨부 가능)
// type : text=0, html=1, text+html=2
define('CUSTOM_SMTP', '');
function mailer($fname, $fmail, $to, $subject, $content, $type=0, $file="", $cc="", $bcc="")
{
global $config;
global $g5;
// 메일발송 사용을 하지 않는다면
if (!$config['cf_email_use']) return;
if ($type != 1)
$content = nl2br($content);
$mail = new PHPMailer(); // defaults to using php "mail()"
if ($config['cf_email_smtp'] == 'Sendmail') {
// 센드메일 사용
if (defined('G5_SMTP') && G5_SMTP) {
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = G5_SMTP; // SMTP server
if(defined('G5_SMTP_PORT') && G5_SMTP_PORT)
$mail->Port = G5_SMTP_PORT;
}
} else {
// 기타메일 서비스 사용
switch ($config['cf_email_smtp']) {
case "Daum" :
$smtp_server = 'smtp.daum.net';
break;
case "Naver" :
$smtp_server = 'smtp.naver.com';
break;
}
if (defined('CUSTOM_SMTP') && CUSTOM_SMTP) {
$mail->IsSMTP();
$mail->Host = $smtp_server;
$mail->SMTPAuth = true;
$mail->Port = 465;
$mail->Username = $config['cf_email_id'];
$mail->Password = $config['cf_email_pw'];
$mail->SMTPSecure = "ssl";
//$mail->Encoding = "base64";
}
}
$mail->CharSet = 'UTF-8';
$mail->From = $fmail;
$mail->FromName = $fname;
$mail->Subject = $subject;
$mail->AltBody = ""; // optional, comment out and test
$mail->msgHTML($content);
$mail->addAddress($to);
if ($cc)
$mail->addCC($cc);
if ($bcc)
$mail->addBCC($bcc);
//print_r2($file); exit;
if ($file != "") {
foreach ($file as $f) {
$mail->addAttachment($f['path'], $f['name']);
}
}
return $mail->send();
}
// 파일을 첨부함
function attach_file($filename, $tmp_name)
{
// 서버에 업로드 되는 파일은 확장자를 주지 않는다. (보안 취약점)
$dest_file = G5_DATA_PATH.'/tmp/'.str_replace('/', '_', $tmp_name);
move_uploaded_file($tmp_name, $dest_file);
$tmpfile = array("name" => $filename, "path" => $dest_file);
return $tmpfile;
}
?>
---
카페24 호스팅 (혹은 국내 호스팅) 쓰면 서버내에서 지원되는데요 다른 서버인가요?
답변을 작성하시기 전에 로그인 해주세요.