폼메일 - 메일 받을때 내용을 테이블로 작업해서 받고 싶어요.
본문
폼메일 소스인데 메일로 받을때
내용을 테이블로 작업해서 받고 싶어요.
send파일에서 내용출력하는 부분에 html로 테이블 짜서 넣으면
메일로 html태그가 텍스트로 다 나오는데 혹시 방법이 없을까요?ㅜㅜ
아래 이미지처럼 메일받고 싶어요.
<form name="contactform" method="post" action="send.php">
<div class="formmail">
<ul>
<li><input name="first_name" type="text" class="ipt" size="30" maxlength="50" placeholder="이름" required ></li>
<li><input name="email" type="text" class="ipt" size="30" maxlength="80" placeholder="이메일" required ></li>
<li><input name="telephone" type="text" class="ipt" size="30" maxlength="30" placeholder="연락처" required ></li>
<li><textarea name="comments" cols="50" rows="10" placeholder="문의사항" required ></textarea></td></li>
</ul>
</div>
<div class="formmail_btn">
<span><input type="submit" value="전송하기" class="btn btn-red"></span>
<span><input name="재설정" type="reset" value="다시작성" class="btn btn-black"></span>
</div>
</form>
-----------------------------send
<meta charset="utf-8">
<?php
if(isset($_POST['email'])) {
$email_to = "*** 개인정보보호를 위한 이메일주소 노출방지 ***";
$email_subject = "[폼메일] 문의사항입니다.";
$email_subject = '=?UTF-8?B?'.base64_encode($email_subject).'?=';
function died($error) {
// your error code can go here
echo "<script> alert('메일발송을 실패하였습니다.');";
echo "history.go(-1);";
echo "</script>";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "이름 : ".clean_string($first_name)."\n\n";
$email_message .= "이메일 : ".clean_string($email_from)."\n\n";
$email_message .= "연락처 : ".clean_string($telephone)."\n\n";
$email_message .= "문의사항 : ".clean_string($comments)."\n\n";
// create email headers
$headers = 'From: '.$email_from;
// 제목이 깨질경우 아래 캐릭터셋 적용
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<script>
alert ("메일이 발송되었습니다.\n빠른 시일안에 답변드리겠습니다.");
location.href="form.php";
</script>
<?php
}
?>
답변 1
$headers = 'From: '.$email_from;
->
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: ' . $email_from . "\r\n";
※ https://ko.code-paper.com/php/examples-html-email-with-php