这个想法是让人们从列表中进行选择,每个值都可以将提交内容定向到选定的电子邮件。我对如何实现它有些困惑。我需要你的帮助。
<form action="scripts/request.php" class="contact_form form-style-1 light" novalidate="novalidate" id="header-slogan-form-2-form" style="">
<div class="form-group select-group">
<select class="form-control" name="posttype">
<option value="type-of-post" selected="" disabled="">Post Type</option>
<option value="complaint">Complaint</option>
<option value="feedback-form">Feedback</option>
<option value="suggestion-form">Suggestion</option>
</select></div>
<div class="form-group select-group">
<select class="form-control" name="Department"><option value="department-list" selected="" disabled="">Choice of Department</option>
<option id="acc-mail" value="account-department">Account Department</option>
<option id="tech-mail" value="technical-email">Technical Department</option>
</select>
</div>
<div class="form-group">
<textarea class="form-control" placeholder="Enter Text Here" rows="9" name="POSTAREA"></textarea></div>
<label class="form-group checkbox text-left">
<input type="checkbox" class="check" placeholder="– i agree with terms and condition" name="AGREEMENT">
<span class="lbl lbl-style">– i Agree</span></label>
<p class="text txt-form text-center">
<a href="#header-slogan-form-2" target="_blank" class="smooth"></a>
<ins>Terms & Condition</ins></p>
<button type="submit" data-loading-text="•••" data-complete-text="Completed!" data-reset-text="Try again later..." class="btn btn-block btn-primary mt-30 btn-lg">
<span><b>SEND NOW</b><br></span>
</button>
JS
if($_POST['id'] === "header-slogan-form-2-form") {
$mailto = "general@email.com";
if($_POST['id'] === "acc-mail") {
$mailto = "acc@email.com";
if($_POST['id'] === "tech-mail") {
$mailto = "technical@email.com";
$data_array = json_decode($_POST['data']);
$message = "";
foreach ($data_array as $key => $value) {
if (isset($value->name) && $value->name !== "") {
$message .= $value->name.': '.$value->value.'<br>';
}
}
$subject = "New Post Submission";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (RFC)
$eol = "\r\n";
// main header (multipart mandatory)
$headers = "From: $mailto" . $eol;
$headers .= "Reply-To: $mailto" . $eol;
$headers .= "MIME-Version: 1.0" . $eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
$headers .= "Content-Transfer-Encoding: 7bit" . $eol;
$headers .= "This is a MIME encoded message." . $eol;
// message
$body = "--" . $separator . $eol;
$body .= "Content-Type: text/html; charset=iso-8859-1" . $eol;
$body .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;
$body .= "<div>" . $message . "</div>" . $eol . $eol;
foreach( $_FILES as $file) {
if ( !move_uploaded_file( $file['tmp_name'], dirname(__FILE__) . '/../tmp/' . $file['name'] ) ) {
echo "error upload file: " . $file['name'];
continue;
}
$filename = $file['name'];
$path = dirname(__FILE__) . '/../tmp';
$file = $path . "/" . $filename;
$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));
// attachment
$body .= "--" . $separator . $eol;
$body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
$body .= "Content-Transfer-Encoding: base64" . $eol;
$body .= "Content-Disposition: attachment" . $eol;
$body .= $content . $eol . $eol;
}
$body .= "--" . $separator . "--";
//SEND Mail
if (mail($mailto, $subject, $body, $headers)) {
echo "mail send ... OK"; // or use booleans here
} else {
echo "mail send ... ERROR!";
print_r( error_get_last() );
}
}
我很好奇如何做到这一点。我尝试了几种脚本,但没有用。我希望每个选择都使用不同的电子邮件,并且每个选择只发送一封电子邮件。
我希望你们不要嘲笑我,因为我是新手,并且需要更多的经验。
答案 0 :(得分:0)
您的变量volume(2.0, 9.7, 3.0)
不持有$_POST['id']
。 $ _POST变量仅保存name属性的值。使用jQuery实现此目的。您可以AJAX提交包含所有数据的表格。像这样
header-slogan-form-2-form
或者使用php,您可以通过这种方式实现-
$('.contact_form).on('submit', function(){
var that = $(this);
var yourVariable = that.attr('id').val();
console.log(yourVariable); //outputs header-slogan-form-2-form to the console
$.ajax({
//your ajax code here!
});
});