所以当我点击" skicka"(发送瑞典语)按钮时,我创建了一个向我发送电子邮件的表单。它100%工作,我测试它,或者说它工作。由于我有一个下拉菜单来更改电子邮件地址/表单操作,因此它非常适用。我尝试使用javascript chgAction(),我也尝试了不同的方法,但这看起来最简单。事情错了,但我不知道是什么,因为我不再收到任何电子邮件。这是一种合法的做法吗?
继承我的index.php
注意:kontakt.php和kontakt2.php都可以使用,因为我事先没有尝试过两种形式的动作=""。
<?php session_start() ?>
<!DOCTYPE HTML>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>HS Konsult</title>
<meta name="description" content="" /><meta name="keywords" content="" /><!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]--><script src="js/jquery.min.js"></script><script src="js/jquery.scrollex.min.js"></script><script src="js/jquery.scrolly.min.js"></script><script src="js/skel.min.js"></script><script src="js/init.js"></script><noscript>
<link rel="stylesheet" href="css/skel.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-xlarge.css" />
</noscript><!--[if lte IE 8]><link rel="stylesheet" href="css/ie/v8.css" /><![endif]--><!--[if lte IE 9]><link rel="stylesheet" href="css/ie/v9.css" /><![endif]-->
</head>
<body><!-- Header -->
<section id="header">
<header class="major">
<h1>HS Konsult</h1>
<p>En Hemsida om oss och vilka tjänster vi erbjuder.</p>
</header>
<div class="container">
<ul class="actions">
<li><a class="button special scrolly" href="#one">Gå Vidare</a></li>
</ul>
</div>
</section>
<!-- Two -->
<section class="main special" id="two">
<div class="container"><span class="image fit primary"><img alt="" src="" /></span>
<div class="content">
<header class="major">
<h2>Vad Gör Vi?</h2>
</header>
<p>Consequat sed ultricies rutrum. Sed adipiscing eu amet interdum lorem blandit vis ac commodo aliquet vulputate.</p>
<ul class="icons-grid">
<li><!--<span class="icon major fa-camera-retro"></span> -->
<h3><img alt="Peo" src="/img.jpg" style="width: 150px; height: 150px;" /></h3>
</li>
<li><!--<span class="icon major fa-pencil"></span> -->
<h3><img alt="Camilla" src="/2.jpg" style="width: 150px; height: 150px;" /></h3>
</li>
<li>
<h3><a href="Camilla.html" title="Läs Mer Om Camilla">Camilla</a></h3>
</li>
<li>
<h3><a href="Peo.html" title="Läs Mer Om Peo">Peo</a></h3>
</li>
</ul>
</div>
<a class="goto-next scrolly" href="#three">Next</a></div>
</section>
<!-- Footer -->
<section id="footer">
<div class="container">
<header class="major">
<h2>Kontakta Oss</h2>
</header>
<?php
//tillagd1
//init variables
$cf = array();
$sr = false;
if(isset($_SESSION['cf_returndata'])){
$cf = $_SESSION['cf_returndata'];
$sr = true;
}
?>
<ul id="errors" class="<?php echo ($sr && !$cf['form_ok']) ? 'visible' : ''; ?>">
<?php
if(isset($cf['errors']) && count($cf['errors']) > 0) :
foreach($cf['errors'] as $error) :
?>
<li><?php echo $error ?></li>
<?php
endforeach;
endif;
?>
</ul>
<!--function to run phpfile depending on person selected-->
<script type="application/javascript">
function chgAction() {
console.log('chgAction()');
console.log(form.selectperson.selectedIndex);
if(form.selectperson.selectedIndex=="option1" )
{document.maillista.action = "/kontakt.php";}
else if(form.selectperson.selectedIndex=="option2")
{document.maillista.action = "/kontakt2.php";}
}
</script>
<form id="maillista" name="maillista" action="/" method="post">
<fieldset>
<p>
<label>Välj Person Att Kontakta</label>
<Select class="target"id=selectperson name="selectperson" onChange="javascript:chgAction()">
<option value ="option1">Peo</option>
<option value ="option2">Camilla</option>
</Select>
</p>
<div class="row uniform">
<div class="6u 12u$(xsmall)"><input id="name" name="name" placeholder="Namn" type="text" /></div>
<div class="6u$ 12u$(xsmall)"><input id="email" name="email" placeholder="john.doe@email.com" type="email" /></div>
<div class="12u$"><textarea id="message" name="message" placeholder="Meddelandet måste vara längre än 20 karaktärer." data-minlength="20" rows="4"></textarea></div>
<div class="12u$">
<ul class="actions">
<li><input class="special" type="submit" name="submit" value="Skicka" id="button1"/></li>
</ul>
</div>
</div>
</fieldset>
</form>
<?php unset($_SESSION['cf_returndata']); ?>
</div>
<
<footer>
<ul class="icons"><!-- <li><a href="#" class="icon alt fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon alt fa-facebook"><span class="label">Facebook</span></a></li>
<li><a href="#" class="icon alt fa-instagram"><span class="label">Instagram</span></a></li>
<li><a href="#" class="icon alt fa-dribbble"><span class="label">Dribbble</span></a></li>
<li><a href="#" class="icon alt fa-envelope"><span class="label">Email</span></a></li> -->
</ul>
<ul class="copyright">
<li>© HS</li>
<li>Design:</li>
</ul>
</footer>
</section>
</body>
</html>
&#13;