0
전자 메일이 자동 생성 첨부 파일 (.txt)과 함께 전송되는 연락처 양식을 작성하고 싶습니다. 첨부 파일에는 연락처 양식에있는 입력 필드의 모든 값 (비어 있는지 여부)이 포함되어야합니다. PHP mail()을 사용하여이 작업을 수행 할 수 있습니까? 내 코드는 이제 전자 메일 본문으로 문의 양식 내용을 보낼 수 있습니다연락처 양식의 컨텐츠 자동 첨부 및 이메일로 보내기
<?php
define("WEBMASTER_EMAIL", '[email protected]');
error_reporting (E_ALL);
if(!empty($_POST))
{
$_POST = array_map('trim', $_POST);
$name = htmlspecialchars($_POST['name']);
$email = $_POST['email'];
$subject = htmlspecialchars($_POST['subject']);
$message = htmlspecialchars($_POST['message']);
$error = array();
if(empty($name))
{
$error[] = 'Please enter your name';
}
if(empty($email))
{
$error[] = 'Please enter your e-mail';
}
elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$error[] = 'e-mail is incorrect';
}
if(empty($message) || empty($message{15}))
{
$error[] = "Please enter message more than 15 characters";
}
if(empty($error))
{
$body = '
<html>
<head>
<title></title>
</head>
<body>
<table>
<tr><td>Name: </td><td> </td><td>'.$name.'</td><tr>
<tr><td> </td><td> </td><td> </td></tr>
<tr><td>Email: </td><td> </td><td>'.$email.'</td><tr>
<tr><td> </td><td> </td><td> </td></tr>
<tr><td>Subject: </td><td> </td><td>'.$subject.'</td><tr>
<tr><td> </td><td> </td><td> </td></tr>
<tr><td>Message: </td><td> </td><td>'.stripslashes($message).'</td><tr>
</table>
</body>
</html>
';
$mail = mail(WEBMASTER_EMAIL, 'Message sent from website', $body,
"MIME-Version: 1.0" . "\r\n"
."Content-type: text/html; charset=UTF-8" . "\r\n"
."From: ".$email." \r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail)
{
echo 'OK';
}
}
else
{
echo '<div class="notification_error">'.implode('<br />', $error).'</div>';
}
}
?>