我正在尝试创建一些 HTML ,它会将电子邮件发送到可变收件人地址。我当前的 HTML 在服务器端成功运行,这很好,但它依赖于固定的电子邮件收件人地址。我不想要这个 - 我想要一个可变的电子邮件收件人地址,在表格中输入收件人的详细信息。
服务器端支持团队已通知我需要使用 Javascript 来检索需要进入电子邮件地址的变量详细信息(标识为" !!!!变量!! !@coke.com"在下面的HTML中。
任何人都可以提供有关如何执行此操作的任何指导吗?这适用于Intranet站点。我不想验证用户输入的内容,但是如果我可以添加固定的CC地址,这将非常有用。
HTML如下所示。
提前致谢,
史蒂夫
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--[if lt IE 7 ]>
<html class="ie ie6" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<![endif]-->
<!--[if IE 7 ]>
<html class="ie ie7" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<![endif]-->
<!--[if IE 8 ]>
<html class="ie ie8" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<![endif]-->
<!--[if IE 9 ]>
<html class="ie ie9" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Test</title>
<link href="/homepage/survey/Coke-new/css/base.css" media="screen" rel="stylesheet" type="text/css" />
<!-- Do not edit the base file, use custom.css -->
<link href="/homepage/survey/Coke-new/css/custom.css" media="screen" rel="stylesheet" type="text/css" />
<!-- Your customisations go here -->
<script src="/stylesheets/jquery/jquery.js" type="text/javascript"></script>
<link href="/online/css/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="/homepage/survey/Coke-new/js/library.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="validate.js"></script>
<script type="text/javascript" src="/stylesheets/misc.js"></script>
<!-- navigation menu style -->
</head>
<body>
<!-- Accessibility Skip To -->
<ul id="skip" class="visuallyhidden">
<!-- <li><a href="#left-nav">Skip to navigation</a></li> Use when leftCol is in use -->
<li><a href="#body-content">Skip to content</a></li>
</ul>
<!-- End Accessibility Skip To -->
<div id="top-band">
<!-- DHS Global Navigation -->
<!-- End Global Navigation -->
</div>
<div id="bodyWrap">
<div class="page">
<!-- Header Section including Logo, Narrow Colour Band and Utilities Navigation -->
<div class="head clearfix">
<!-- Program Logo -->
<div id="Coke-logo">
<a href="/">Coke logo</a>
</div>
<!-- End Program Logo -->
<!-- Utilities Navigation -->
<!--End Utilities Navigation -->
<!-- Application Name -->
<div id="app-title">
<span>Form Examples</span>
</div>
<!-- End Application Name -->
</div>
<!-- End Header section -->
<!-- Content section including Body Content, left and right columns -->
<div class="body">
<!-- Section containing main website content -->
<!-- Left Column class="leftCol" -->
<!-- End Left Column -->
<!-- Right Column class="rightCol" -->
<!-- End Right Column -->
<div class="main" id="body-content">
<!-- Start of actual page content -->
<h1>Form Examples</h1>
<script language="javascript">
function replaceNewLines2(newChar)
{
if (!newChar) { var newChar = " "; }
var allTextAreas = document.getElementsByTagName("textarea");
alert("TA L "+ allTextAreas.length);
for (var i = 0; i < allTextAreas.length; i++)
{
allTextAreas[i].value = allTextAreas[i].value.replace(/[\n]/g, newChar);
}
}
</script>
<h2 class="h3">Example 1 - Stacked form fields in 1 column</h2>
<div id="ValidateFail" class="error-box hidden"><strong>At least one of the required fields in this form has not been completed</strong>.</div>
<form action="/cgi-bin/feedback" method="post" name="dummyform1" id="dummyform1" class="vertical-form" onsubmit="return validateStacked();" >
<input type="hidden" name="email" value="!!!! Variable!!!@coke.com" />
<!--input type="hidden" name="tfile" value="/homepage/survey/Coke-new/test.csv" />
<input type="hidden" name="csv" value="1" /--->
<input type="hidden" name="subject" value="Form Feedback" />
<!--output can only be a intranet page, use the redirect meta tag in the thankyou page to redirect user to COKE -->
<input type="hidden" name="output" value="/homepage/survey/Coke-new/thankyou.html" />
<div>
<label for="dummy0">Text input - no width specified</label>
<input type="text" name="dummy0" id="dummy0" />
</div>
<div>
<label for="dummy1">Text input - with required field <span class="required">(required)</span></label>
<input type="text" name="dummy1" id="dummy1" />
<div class="warninginfo hidden" id="dummy1Val">TExt input required</div>
</div>
<div>
<label for="dummy2">Text input - size = 10 characters</label>
<input type="text" name="dummy2" id="dummy2" size="10" />
</div>
<div>
<label for="dummy3">Text input <span class="label-info-box"> class = size1of2 (50% width of container)</span></label>
<input type="text" name="dummy3" id="dummy3" class="size1of2" />
</div>
<div>
<label for="dummy4">Text input - class = size1of1 (100% width of container)</label>
<input type="text" name="dummy4" id="dummy4" class="size1of1" />
</div>
<div>
<label for="dummy5">Textarea <span class="required">(required)</span></label><br />
<textarea name="dummy5" id="dummy5" rows="5" cols="40" ></textarea>
<div class="warninginfo hidden" id="dummy5Val">TExt input required</div>
</div>
<fieldset class="inline">
<legend>Radio buttons with inline inputs - contained in a fieldset </legend>
<input type="radio" id="example11" name="name11" />
<label for="example11">Radio option one</label>
<input type="radio" id="example12" name="name11" />
<label for="example12">Radio option two</label>
<input type="radio" id="example13" name="name11" />
<label for="example13">Radio option three</label>
</fieldset>
<fieldset>
<legend>Radio buttons with seperate line inputs - contained in a fieldset <span class="required">(required)</span></legend>
<div id="radioValDiv">
<div class="inline">
<input type="radio" name="example21" id="example21"/>
<label for="example21">Radio option one</label>
</div>
<div class="inline">
<input type="radio" name="example21" id="example22"/>
<label for="example22">Radio option two</label>
</div>
<div class="inline">
<input type="radio" name="example21" id="example23"/>
<label for="example23">Radio option three</label>
</div>
</div>
</fieldset>
<div class="warninginfo hidden" id="example21Val">Select Radio button</div>
<div id="example31Div">
<fieldset class="inline">
<legend>Checkbox with inline inputs - contained in a fieldset <span class="required">(required)</span></legend>
<input type="checkbox" id="example31" name="name31" value="name31a"/>
<label for="example31">Check option one</label>
<input type="checkbox" id="example32" name="name31" value="name31b"/>
<label for="example32">Check option two</label>
<input type="checkbox" id="example33" name="name31" value="name31c"/>
<label for="example33">Check option three</label>
</fieldset>
</div>
<div class="warninginfo hidden" id="example31Val">Select a Check box</div>
<div>
<input type="submit" value="Submit" class="btn-primary" />
<input type="reset" value="Reset" class="btn-reg" onclick="window.location.reload();"/>
</div>
</form>
</div>
<!-- end body-content -->
</div>
<!-- end Content section -->
</div>
</div>
<!-- end bodywrap -->
<!-- Page footer containing wide colour-band and footer links -->
<!-- Footer section -->
<div class="foot clearfix">
<div class="dhs-program-band">
<span class="prg-1"></span>
<span class="prg-2"></span>
<span class="prg-3"></span>
<span class="prg-4"></span>
<span class="prg-5"></span>
<span class="prg-6"></span>
<span class="prg-7"></span>
<span class="prg-8"></span>
<span class="prg-9"></span>
<span class="prg-10"></span>
<span class="prg-11"></span>
<span class="prg-12"></span>
<span class="prg-13"></span>
<span class="prg-14"></span>
<span class="prg-15"></span>
<span class="prg-16"></span>
<span class="prg-17"></span>
</div>
<div class="page">
<ul id="footer-nav">
<li class="last">
<a href="/">Coke Intranet</a>
</li>
</ul>
<div id="unity-star">Coke</div>
</div>
</div>
<!-- end Footer section -->
<!-- Call Javascript before closing body tag: See http://developer.yahoo.com/performance/rules.html -->
</body>
</html>
==========================================
所以,因此......只是试图找出添加这些代码片段的位置......这是我需要改变的吗?
BEFORE
<!--[if (gt IE 9)|!(IE)]><!-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!--<![endif]-->
AFTER
<!--[if (gt IE 9)|!(IE)]><!-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'Cc: check@coke.com . "\r\n";
mail($_POST['email'], "subject", "message", $headers);
<!--<![endif]-->
然后对于第二部分,我要替换:
BEFORE:
<script language="javascript">
function replaceNewLines2(newChar)
AFTER:
<script language="javascript">
if (isset($_POST['email'@coke.com]) && filter_var ($_POST'email'@coke.com], FILTER_VALIDATE_EMAIL)) {
echo "email valid";!
$email = $_POST['email'@coke.com];
}else{ echo "email not valid"; $email = "check@coke.com"; }
function replaceNewLines2(newChar)
添加的代码是否需要函数头?
更多问题:
$ _POST会显示一个弹出窗口,要求输入名称吗?我可以在此弹出窗口中添加标签,以便人们知道为什么要求提供电子邮件地址吗?
代码会发生什么&#34; value =&#34; !!!! Variable!!!@coke.com" /&#34;我是否只删除此引用?
还是很困惑......
答案 0 :(得分:0)
在你PHP mail function中你应该使用$ _POST ['email']作为第一个参数:mail($_POST['email'], "subject", "message");
如果您需要CC地址,可以使用第四个可选参数,该参数可以包含其他标题。
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
mail($_POST['email'], "subject", "message", $headers);
您必须验证用户输入以确保它是有效的电子邮件地址。 小例子:
if (isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
echo "email valid";!
$email = $_POST['email'];
}else{
echo "email not valid";
$email = "your-email@mail.com";
}