폼메일 발송후 이동과 줄바꿈 문의드립니다.
관련링크
본문
https://sir.kr/g5_skin/20940?sfl=wr_subject%7C%7Cwr_content&stx=formmail 이 스킨을 변형해서 그누보드와 관계없는 페이지에 사용하고있습니다.
<!DOCTYPE html>
<html lang="en">
<head>
<title>KIMS</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body>
<!-- Header -->
<header class="w3-display-container w3-content w3-center" style="max-width:1500px">
<img class="w3-image" src="img/photographer.jpg" alt="Me" width="1500" height="600">
<div class="w3-display-middle w3-padding-large w3-border w3-wide w3-text-light-grey w3-center">
<h1 class="w3-hide-medium w3-hide-small w3-xxxlarge">JANE DOE</h1>
<h5 class="w3-hide-large" style="white-space:nowrap">JANE DOE</h5>
<h3 class="w3-hide-medium w3-hide-small">PHOTOGRAPHER</h3>
</div>
<!-- Navbar (placed at the bottom of the header image) -->
<div class="w3-bar w3-light-grey w3-round w3-display-bottommiddle w3-hide-small" style="bottom:-16px">
<a href="#" class="w3-bar-item w3-button">Home</a>
<a href="#portfolio" class="w3-bar-item w3-button">Portfolio</a>
<a href="#contact" class="w3-bar-item w3-button">Contact</a>
</div>
</header>
<!-- Navbar on small screens -->
<div class="w3-center w3-light-grey w3-padding-16 w3-hide-large w3-hide-medium">
<div class="w3-bar w3-light-grey">
<a href="#" class="w3-bar-item w3-button">Home</a>
<a href="#portfolio" class="w3-bar-item w3-button">Portfolio</a>
<a href="#contact" class="w3-bar-item w3-button">Contact</a>
</div>
</div>
<!-- Page content -->
<div class="w3-content w3-padding-large w3-margin-top" id="portfolio">
<!-- Images (Portfolio) -->
<img src="img/ocean.jpg" alt="Ocean" class="w3-image" width="1000" height="500">
<img src="img/ocean2.jpg" alt="Ocean II" class="w3-image w3-margin-top" width="1000" height="500">
<img src="img/falls2.jpg" alt="Falls" class="w3-image w3-margin-top" width="1000" height="500">
<img src="img/mountainskies.jpg" alt="Skies" class="w3-image w3-margin-top" width="1000" height="500">
<img src="img/mountains2.jpg" alt="Mountains" class="w3-image w3-margin-top" width="1000" height="500">
<!-- Contact -->
<div class="w3-light-grey w3-padding-large w3-padding-32 w3-margin-top" id="contact">
<h3 class="w3-center">Contact</h3>
<hr>
<p>Mauris neque quam, fermentum ut nisl vitae, convallis maximus nisl. Sed mattis nunc id lorem euismod placerat. Vivamus porttitor magna enim, ac accumsan tortor cursus at. Phasellus sed ultricies mi non congue ullam corper. Praesent tincidunt sed tellus.</p>
<form name="contactForm" id="contactForm" action="formmail/php/contact.php" target="_blank" method="POST" autocomplete="off">
<div class="w3-section">
<label for="contact_name">Name</label>
<input class="w3-input w3-border" type="text" required id="contact_name" name="contact_name" title="Name" placeholder="Name">
</div>
<div class="w3-section">
<label for="contact_email">Email</label>
<input class="w3-input w3-border" type="text" required id="contact_email" name="contact_email" title="Email" placeholder="Email">
</div>
<div class="w3-section">
<label for="contact_phone">Phone</label>
<input class="w3-input w3-border" type="text" required id="contact_phone" name="contact_phone" title="Phone" placeholder="Phone">
</div>
<div class="w3-section">
<label for="contact_subject" >Subject</label>
<input class="w3-input w3-border" type="text" required id="contact_subject" name="contact_subject" title="Subject" placeholder="Subject">
</div>
<div class="w3-section">
<label for="contact_message" class="">내용</label>
<textarea class="w3-input w3-border" id="contact_message" name="contact_message" rows="10" title="Message" placeholder="Message"></textarea>
</div>
<!-- <button type="submit" class="w3-button w3-block w3-dark-grey">Send</button>-->
<div class="btn_confirm">
<input class="w3-green" id="contact_submit" type="submit" class="btn_submit" value="SEND MESSAGE">
</div>
</form>
<br>
<p>Powered by <a href="https://www.w3schools.com/w3css/default.asp" target="_blank" class="w3-hover-text-green">w3.css</a></p>
</div>
<!-- End page content -->
</div>
</body>
</html>
위의 폼으로 발송하고 action파일은 다음과 같습니다.
<?php
/** ****************************************** **
* @CONTACT FORM V1.1
* @AUTHOR Dorin Grigoras
* @DATE Tuesday, October 21, 2014
** ****************************************** **/
session_start();
@ini_set('display_errors', 0);
@ini_set('track_errors', 0);
@date_default_timezone_set('Asia/Seoul'); // Used only to avoid annoying warnings.
if($_REQUEST['action'] = 'email_send') {
// BEGIN
require('config.inc.php');
$array['contact_name'] = isset($_REQUEST['contact_name']) ? strip_tags(trim($_REQUEST['contact_name'])) : '';
$array['contact_email'] = isset($_REQUEST['contact_email']) ? strip_tags(trim($_REQUEST['contact_email'])) : '';
$array['contact_phone'] = isset($_REQUEST['contact_phone']) ? strip_tags(trim($_REQUEST['contact_phone'])) : '-';
$array['contact_classficationl'] = isset($_REQUEST['contact_classfication']) ? strip_tags(trim($_REQUEST['contact_classfication'])) : '';
$array['contact_subject'] = isset($_REQUEST['contact_subject']) ? strip_tags(trim($_REQUEST['contact_subject'])) : $config['subject'];
$array['contact_message'] = isset($_REQUEST['contact_message']) ? trim(strip_tags($_REQUEST['contact_message'], '<b><a><strong>')) : '';
$array['contact_captcha'] = isset($_REQUEST['contact_captcha']) ? strip_tags(trim($_REQUEST['contact_captcha'])) : '-';
// Check email
if(ckmail($array['contact_email']) === false) die('_invalid_email_');
// Check required fields
if($array['contact_name'] == '' || $array['contact_email'] == '' || $array['contact_message'] == '') die('_required_');
/* if($array['contact_captcha'] != $_SESSION['captcha']) die('_invalid_captcha_'); */
// Visitor IP:
$ip = ip();
// DATE
$date = date('l, d F Y , H:i:s');
// Optional - if completed!
$PHONE = ($array['contact_phone'] != '') ? "<b>Phone:</b> {$array['contact_phone']} <br>" : null;
$SUBJECT = ($array['contact_subject'] != '') ? "<b>Subject:</b> {$array['contact_subject']} <br>" : null;
$mail_body = "
<b>Date:</b> {$date} <br>
<b>Name:</b> {$array['contact_name']} <br>
<b>Email:</b> {$array['contact_email']} <br>
{$PHONE}
<br>
{$SUBJECT}
<b>Message:</b> {$array['contact_message']} <br>
--------------------------------------------------- <br>
IP: {$ip}
";
// SMTP ENABLED [isset = for old versions]
if(!isset($config['use_smtp']) || isset($config['use_smtp']) && $config['use_smtp'] === true) {
require('phpmailer/5.1/class.phpmailer.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->AddAddress($config['send_to'], 'Contact Form');
$m->AddReplyTo($array['contact_email'], $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);
}
// mail()
else {
// mail( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
mail(
$config['send_to'] ,
$array['contact_subject'],
$mail_body
);
}
}
/** **********************************
@CHECK EMAIL
/** ******************************* **/
function ckmail($email) {
$email = trim(strtolower($email));
if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/',trim($email))){
return $email;
} else { return false; }
}
/** **********************************
@VISITOR IP
/** ******************************* **/
function ip() {
if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); }
elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); }
elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); }
elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); }
elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); }
else { $ip = $_SERVER['REMOTE_ADDR']; }
return $ip;
}
?>
메일은 오는데요.
메세지 글쓰기 textarea에서 엔터로 줄바꿈을해도 발송된 폼메일에는 줄바꿈이 되지 않습니다.
줄바꿈을 하는 방법은 어떻게 하면 될런지요.
그리고
메일발송이 성공되면 _sent_ok_라는 메세지가 나옵니다._sent_ok_를 클릭하면 이동이 되거나 아니면 원하는 메뉴로 이동하는 방법이 있는지요.
단일 페이지로 만들어서 index.php안에서 메일발송후 원하는 메뉴로 이동하고 싶습니다. 예를들면 #Portfolio 메뉴로 이동하고싶습니다.
고수님들의 조언을 구합니다. 감사합니다.
!-->!-->
답변 5
저 같은 경우는 textarea 의 문자열을 submit 버튼 온클릭시에 replace 해서 날립니다만...
로직 순서가 언제나 온클릭이 먼저이고 그 다음에 submit 라서요.
<textarea id="my" name="my"></textarea>
<input id="submitBtn" type="submit">
<script>
submitBtn.onclick = function() {
my.value = my.value.replaceAll("\n", "<br>");
}
</script>
자동으로 줄바 꿈 되어서 보이게 할려면 기본적으로 nl2br(); 이 함수를 쓰면 메일보는 곳에서 이렇게 하면 보일 것입니다.
메세지 부분을 편집기를 사용하면 보내면 줄 바꿈과 색상등이 반영된 메세지가 보일 것입니다.
<b>Message:</b> {nl2br($array['contact_message'])} <br>
저 부분처럼 변경해 보세요.
감사합니다.^^
철용님 쪽지 보세요.