我在 php 创建的 html 页面上有一个按钮,单击 javascript 函数将特定元素值发布到另一个 php 页面,执行 mysql 查询,创建 html 电子邮件并自动发送,无需用户交互。效果很好。
现在已请求一个额外的步骤,以便能够查看电子邮件并可能在发送之前对其进行编辑,但我缺乏如何执行此操作的概念。最好不要破坏我已经拥有的代码。
也许像一个消息框......你想查看电子邮件(是/否)否继续发送电子邮件,是允许它被编辑。
任何想法或输入都会很棒。
添加当前代码:
第1页.php
echo "<td>";
if ($x == "Y"){$sent1 = "Y"; $checkcolor1 = 'images/greencheck.jpg';} else {$sent1 = "N"; $checkcolor1 = 'images/redcheck.jpg';}
echo "<div id='stepA$a' title='$sent1$a' value='$mycode'><a id='$a' href='' class ='step1'><div id='stepB$a'><img src='$checkcolor1' title='Send Rental Agreement' border='0' height='24' width='24'></img></div></a></div>";
echo "</td>";
Javascript 函数
$(".step1").on("click", function () {
var element = $(this);
var I = element.attr("id");
var id = $("#id" + I).val();
var checkname1 = $("#stepA" + I).attr("title");
var code = $("#stepA" + I).attr("value");
$.post("page2.php", {
id: id, checkname1: checkname1, code: code
},
function (data) {
var response = (data).split(";", 2);
$("#stepA" + I).attr("title", (response[0]));
$("#stepB" + I).html(response[1]);
$("#stepB" + I).hide();
$("#stepB" + I).fadeIn(1500);
});
return false;
});
Page2.php
<?php
include('connection.php');
$mycode = $_POST['code'];
if (empty($mycode)) {die("No Value");}
$result = mysql_query("SELECT code FROM code WHERE code = '$mycode'") or die ( mysql_error ());
if (mysql_num_rows($result) > 0) {
$id=$_POST['id'];
$checkname1=$_POST['checkname1'];
$rest = $checkname1 [0];
if ($rest == "Y"){
$checkchange1 ="Y$id";
$checkchange2 ="<img src='images/greencheck.jpg' title='Send Rental Agreement' border='0' height='24' width='24'></img>";
echo $checkchange1.";".$checkchange2.";";
} else {
$change="Y";
$query = "UPDATE info SET invoice = '$change' WHERE id = $id";
$result = mysql_query($query) or die ( mysql_error ());
$query = "SELECT * FROM info WHERE id = '$id'";
$result = mysql_query($query) or die ( mysql_error ());
if (mysql_num_rows($result) > 0) {
while(list($a,$b,$c,$d,$e) = mysql_fetch_row($result)) {
$mail_body ='
<img src="images/logo.png" alt="Logo" width="174" height="70"></img><br />
<p><b>HTML Email body</b></p>';}
$to = $e;
$headers = 'MIME-Version: 1.0' . "\r\n" .
'Content-Type: text/html; charset=ISO-8859-1' . "\r\n" .
'From: Rental<hell@test.com>' . "\r\n" .
'Reply-To: hello@test.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$subject = 'Rental Agreement ' . $d . ', ' . $l . ' - ' . $m;
mail($to, $subject, $mail_body, $headers);
$checkchange1 ="Y$id";
$checkchange2 ="<img src='images/greencheck.jpg' title='Send Rental Agreement' border='0' height='24' width='24'></img>";
echo $checkchange1.";".$checkchange2.";";
}
}
}
}
?>
更新:我按照建议下载了 TinyMCE 并进行了以下更改。我还有 3 个问题。
1 - TinyMCE 没有显示任何图像,所以我需要调查一下。2 - 虽然它允许我对其进行编辑....对电子邮件或源的任何编辑实际上都不是在单击按钮时提交的。3 - 电子邮件底部显示了我看不到或找不到的 html 代码……所以仍在调查。
我已将我的 javascript 更改为以下内容 -
$(".step5").on("click", function () {
var element = $(this);
var I = element.attr("id");
var code = $("#stepI" + I).attr("value");
var checkname = $("#stepI" + I).attr("title");
$("#email").html("<h3>Loading</h3>").css("display", "block");
$.get("emailtest1.php?code=" + code + "&id=" + I + "&checkname=" + checkname , function (data) {
$("#email").html(data);
$("#snd").click(function () {
var send_to = document.getElementById("addy").value;
var email_body = document.getElementById("content").value;
$("#email").append("<br /><br /><div><i>Sending...</i></div>");
$.post("emailtest1.php?code=" + code, {
mode: "snd", send_to: send_to, email_body: email_body
}, function (data) {
var response = (data).split("z",3);
$("#email").html(response[0]);
$("#stepI" + I).attr("title", (response[1]));
$("#stepJ" + I).html(response[2]);
$("#stepJ" + I).hide();
$("#stepJ" + I).fadeIn(1500);
});
});
$("#cnx").click(function () {
$.post("emailtest1.php?code=" + code, {
mode: "cnx"
}, function (data) {
$("#email").html(data);
});
});
});
});
我将 page1.php 更改为以下内容
echo "<td>";
if ($x == "Y"){$sent1 = "Y"; $checkcolor1 = 'images/greencheck.jpg';} else {$sent1 = "N"; $checkcolor1 = 'images/redcheck.jpg';}
echo "<div id='stepI$a' title='$sent1$a' value='$mycode'><a id='$a' href='#' class ='step5'><div id='stepJ$a'><img src='$checkcolor1' title='Email Test' border='0' height='24' width='24'></img></div></a></div>";
echo "<div id='email'></div>";
我将 page2.php 更改为以下内容
function showForm(){
$id = $_GET['id'];
$checkname =$_GET['checkname'];
$rest = $checkname [0];
$mail_body =' the body of my email';}
echo '<script type="text/javascript">
tinymce.init({
selector: "textarea",
auto_focus: "elm1",
width: 1100,
height: 2500,
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
</script>
<h3>Email To Send</h3>
<form name="mf" id="mf" method="post" action="">
<p><label>Address :</label><input type="text" size="35" name="addy" id="addy" value="'.$e.'"/></p>
<textarea name="content" id="content" style="width:100%" value="\''.$clean_mail_body.'\'"></textarea>
<p><a href="#" class="btn" id="snd" name="snd"><img src="images/submitbutton.jpg" title="Send Email" border="0" height="25" width="75"></img></a><a href="#" class="btn" id="cnx" name="cnx"> <img src="images/cancelemail.jpg" title="Send Email" border="0" height="25" width="80"></img></a></p>
</form>';
}
}
}
function cnxForm(){
echo '<a href=""><img src="/images/logo.png"></a><br/><h3>Email Not Sent</h3><script type="text/javascript">setTimeout(\'$("#email").fadeOut("fast")\',2000);</script>';
}
function sndForm(){
$send_to = $_POST['send_to'];
$email_body = $_POST['email_body'];
$headers = 'MIME-Version: 1.0' . "\r\n" .
'Content-Type: text/html; charset=ISO-8859-1' . "\r\n" .
'From: Rental<test@test.com>' . "\r\n" .
'Reply-To: test@test.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$subject = 'Rental Agreement';
mail($send_to, $subject, $email_body, $headers);
$checkchange0 ='<a href=""><img src="/images/logo.png"></a><br/><h3>Email Sent</h3><script type="text/javascript">setTimeout(\'$("#email").fadeOut("fast")\',2000);</script>';
$checkchange1 ="Y$id";
$checkchange2 ="<img src='images/greencheck.jpg' title='Send Rental Agreement' border='0' height='24' width='24'></img>";
echo $checkchange0."z".$checkchange1."z".$checkchange2."z";
}
$mode=(!empty($_GET['mode']))?$_GET['mode']:$_POST['mode'];
switch($mode){
case 'snd': sndForm();break;
case 'cnx': cnxForm();break;
default: showForm();break;
}
}