- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有这个 php 代码,我想用它向用户发送电子邮件。发送邮件后,弹出窗口将指定邮件已发送。但是,当我键入邮件正文的基本结构时,当我尝试将信息包含在表格中时出现错误。以下是代码和错误:
PHP(发送电子邮件)(sendmail.php)
<?php
include_once "connect.php";
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$form=$_POST;
$accountnumber=$form['accountnumber'];
$trade=$form['tradetype'];
$metal=$form['metal'];
$amount=$form['amount'];
$date=$form['date'];
$stmt = $conn->prepare("SELECT * FROM Customers WHERE CustomerCode='$accountnumber'");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$stmt1 = $conn->prepare("SELECT * FROM Contracts WHERE Trade='$trade' AND Metal='$metal' AND Amount='$amount' AND ExpiryDate='$date'");
while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) {
$to= $row['Email'];
$subject= "Bullion Assets Management_Trade Order Confirmation - <?php print strftime('%d %B %Y');?>
$body = "<table>;
$body .="<tr>";
$body .="<td>"Dear $row['Name']; "</td>"
$body .="</tr>";
$body .="<tr>";
$body .="<td>"Fixed Minimum $trade Price Pre-Order Confirmation"</td>";
$body .="</tr>";
$body .="<tr>";
$body .="<td>"1) Bullion Assets Management Pte Ltd confirms receipt and accepts your pre-order to $trade $amount of 9999 Pooled Allocated $metal Loco Singapore (“$metal”) on $date London PM Fix at minimum fixed price at USD or higher."</td>";
$body .="</tr>";
$body .="<tr>";
$body .="<td>"2) This pre-order will enable a discount of USD $row1['DiscountPremium']; per oz ( notional value USD $row1[DiscountPremium'];*$amount ) upon your $metal purchase."</td>";
$body .="</tr>";
$body .="<tr>";
$body .="<td>"3) <<IMPORTANT>> - If the PM FIX on the above date is below USD $row1['Price']; per troy oz, you will still be obligated to buy at the minimum price of USD $row1['Price']; per troy oz."</td>";
$body .="</tr>";
$body .="<tr>";
if(isset($trade='Buy') {
$body .="<td>"4) A deposit of SGD 5000 will be required for your pre-order. This deposit will be used to offset the purchase amount upon your $metal purchase."</td>";
} else {
$body .="<td>"4) No deposit is required for your pre-order."</td>";
}
$body .="</tr>";
$body .="<tr>";
$body .="<td>"5) The pre-order minimum buying price and discount cannot be changed or cancelled upon signed confirmation of this order. You can however submit a new selling order at the PM Fix if you do not wish to proceed with your $metal purchase and collection."</td>";
$body .="</tr>";
$body .="<tr>";
$body .="<td>"6) Settlement and/or collection of $metal from Bullion Assets Management Pte Ltd is to be completed within 2 business days from $date."</td>";
$body .="</tr>";
$body .="<tr>";
$body .="<td>"This acknowledgement by you is subject to and constitutes a supplement to the Customer Agreement signed between you and Bullion Assets Management Pte Ltd."</td>";
$body .="</tr>";
$body .="</table>";
});
});
$conn-->close();
$headers = From: "ashwini@goldsilvercentral.com.sg";
$headers .= 'MIME-Version: 1.0\r\n';
$headers .= 'Content-Type: text/html; charset=\"iso-8859-1\"\n';
$headers .= 'X-Priority: 1\r\n';
$headers .= 'X-MSMail-Priority: High\n';
$headers .= 'X-Mailer: PHP". phpversion() ."\r\n';
mail($to, $subject, $body, $headers );
echo "Your Order has been submitted";
}
?>
上述php文件的Jquery
$('#confirm_btn').click(function() {
var accountnumber = $('#accountnumber').val();
var tradetype = $('input.tradetype:checked').val();
var amount = $('#amount').val();
var metal = $('input.metal:checked').val();
var date = $('#date').val();
$.ajax({
type: "POST", /* METHOD TO USE TO PASS THE DATA */
url: "sendorder.php", /* THE FILE WHERE YOU PROCESS THE SELECT QUERY */
data: {"accountnumber": accountnumber, "tradetype": tradetype, "amount": amount, "metal": metal, "date": date}, /* THE DATA WE WILL SUBMIT TO retrievepremordisc.php */
success: function(data){
successmessage = 'sucess';
}
});
});
所以我得到的错误是针对 php 文件的:解析错误:语法错误,第 20 行出现意外的 '>' ($body = ";)
关于错误有什么建议吗?
另外,如何让弹出窗口出现?提前谢谢你!
最佳答案
您的代码中有许多错误,主要与您尝试连接字符串的方式有关,但也与您访问变量和终止 while 循环的方式有关。这是您的代码清理了一下。我无法亲自测试它以确保它能按预期工作,但它至少应该让你走上正确的道路。
include_once "connect.php";
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$accountnumber = isset($_POST['accountnumber']) ? $_POST['accountnumber'] : NULL;
$trade = isset($_POST['tradetype']) ? $_POST['tradetype'] : NULL;
$metal = isset($_POST['metal']) ? $_POST['metal'] : NULL;
$amount = isset($_POST['amount']) ? $_POST['amount'] : NULL;
$date = isset($_POST['date']) ? $_POST['date'] : NULL;
$stmt = $conn->prepare("SELECT * FROM Customers WHERE CustomerCode='$accountnumber'");
$failedEmails=0;
$sentEmails=0;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$stmt1 = $conn->prepare("SELECT * FROM Contracts WHERE Trade='$trade' AND Metal='$metal' AND Amount='$amount' AND ExpiryDate='$date'");
while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) {
$to = $row['Email']; // what are you trying to do here? are you attempting to send the email to serevral addresses at once?
$subject = 'Bullion Assets Management_Trade Order Confirmation -' . strftime('%d %B %Y');
if (isset($trade) && $trade == 'Buy') {
$deposit = '<td>4) A deposit of SGD 5000 will be required for your pre-order. This deposit will be used to offset the purchase amount upon your $metal purchase.</td>';
} else {
$deposit = '<td>4) No deposit is required for your pre-order.</td>';
}
$body = '<table>' .
'<tr><td>Dear' . $row['Name'] . '</td></tr>' .
'<tr><td>Fixed Minimum ' . $trade . ' Price Pre-Order Confirmation</td></tr>' .
'<tr><td>1) Bullion Assets Management Pte Ltd confirms receipt and accepts your pre-order to $trade $amount of 9999 Pooled Allocated $metal Loco Singapore ("' . $metal . '") on $date London PM Fix at minimum fixed price at USD or higher.</td></tr>' .
'<tr><td>2) This pre-order will enable a discount of USD ' . $row1['DiscountPremium'] . ' per oz ( notional value USD ' . $row1['DiscountPremium'] * $amount . ') upon your $metal purchase.</td></tr>' .
'<tr><td>3) <<IMPORTANT>> - If the PM FIX on the above date is below USD ' . $row1['Price'] . ' per troy oz, you will still be obligated to buy at the minimum price of USD ' . $row1['Price'] . ' per troy oz.</td></tr>' .
'<tr>' . $deposit . '</tr>' .
'<tr><td>5) The pre-order minimum buying price and discount cannot be changed or cancelled upon signed confirmation of this order. You can however submit a new selling order at the PM Fix if you do not wish to proceed with your $metal purchase and collection.</td></tr>' .
'<tr><td>"6) Settlement and/or collection of $metal from Bullion Assets Management Pte Ltd is to be completed within 2 business days from $date.</td></tr>' .
'<tr><td>This acknowledgement by you is subject to and constitutes a supplement to the Customer Agreement signed between you and Bullion Assets Management Pte Ltd.</td></tr>' .
'</table>';
$headers = 'From: ashwini@goldsilvercentral.com.sg';
$headers .= 'MIME-Version: 1.0\r\n';
$headers .= 'Content-Type: text/html; charset=\"iso-8859-1\"\n';
$headers .= 'X-Priority: 1\r\n';
$headers .= 'X-MSMail-Priority: High\n';
$headers .= 'X-Mailer: PHP". phpversion() ."\r\n';
mail($to, $subject, $body, $headers) ? $sentEmails++ : $failedEmails++;
}
}
if ($failedEmails==0) echo json_encode(['success' => true, 'message' => 'Your Order has been submitted']);
else echo json_encode(['success' => false, 'message' => 'There was a problem submitting your order. Only '.$sentEmails.' of '.($sentEmails+$failedEmails).' emails were sent.']);
$conn-- > close();
$('#confirm_btn').click(function () {
var accountnumber = $('#accountnumber').val();
var tradetype = $('input.tradetype:checked').val();
var amount = $('#amount').val();
var metal = $('input.metal:checked').val();
var date = $('#date').val();
$.ajax({
type: "POST", /* METHOD TO USE TO PASS THE DATA */
url: "sendorder.php", /* THE FILE WHERE YOU PROCESS THE SELECT QUERY */
dataType: 'json',
data: {
"accountnumber": accountnumber,
"tradetype": tradetype,
"amount": amount,
"metal": metal,
"date": date
}, /* THE DATA WE WILL SUBMIT TO retrievepremordisc.php */
success: function (data) {
if(data.success='true'){
alert(data.message);
// order was submitted
}
else{
alert(data.message);
// order was NOT submitted
}
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
}
});
});
关于使用多个查询发送邮件的 PHP (PDO) 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33687034/
我想在文本区域中向许多其他用户发送电子邮件。在名为内容的文本区域中,如果我键入星号包围的“用户”,我想让它们填写每个电子邮件的用户名(“@”之前的文本)。每封电子邮件中的每个用户名都会产生很多不同。然
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Problem when loading php file into variable (Load resu
我正在从数据库中提取信息,并尝试将其作为电子邮件发送。将从数据库中拉取多行数据。这就是我的代码的样子... 所有的信息邮件都很好。我的问题是,我想保留中断。例如,在标题之后,我想中断一下,然后开始备
当我使用我们使用 java 邮件的门户发送 TEXT 电子邮件时没有问题,但是,当我选择放置 HTML 内容并发送电子邮件时,会引发以下警报。花了几个小时搜索但没有有用的答案! 谁能帮忙 电子邮件主题
我有这个类,它处理 gmail 的登录。无论我输入什么电子邮件和密码,程序都会返回 session 。我不明白如何在返回 session 对象之前检查登录是否成功。 package mailActio
我设置的短信作为文本文件附在信中。我不明白为什么会这样。 replied letter example public void sendEmail(MimeMessage message, Strin
所以我正在制作一个网络系统,这个想法是当用户关闭浏览器时它会向我发送一封电子邮件。目前,用户正在使用 Javascript Ajax 来让 PHP 更新数据库的当前时间。当时间超过 5 分钟时,我希望
我想发送邮件,当产品从之前、日期和之后过期时,在 php 中,我在 php 中使用了 datediff mysql 函数,但如果产品过期日期类似于 31-1-2012 ,则不同值是不适合我的编码,请帮
我正在尝试设置一个邮件脚本,该脚本将首先从 mysql 运行一个简单的选择,并在消息中使用这些数组变量。然而,所有的变量并没有输出到消息体,只有一行变量。这是我的脚本: $sql1 = "SE
我最近一直在努力研究这个问题。是否有我可以使用并添加到其中的 android API?我想为电子邮件应用程序制作一个插件,但我不想制作整个电子邮件应用程序。 我非常想要一些已经可以处理发送和接收电子邮
嗨 我有一个 PHP 西类牙文网站。在此邮件正文中包含一个主题“Solicitud de cotización”,但该主题出现在热门邮箱中,如 Solicitud de cotización 。但它在
我想写一个脚本,使用 php 自动向我的客户发送电子邮件 我如何自动发送它,例如,如果他们输入他们的电子邮件。然后点击提交 我想自动发送这封邮件 其次,我的主机上是否需要 smtp 服务器?我可以在任
今天早上我已经解决了一个问题: Java Mail, sending multiple attachments not working 这次我遇到了一个稍微复杂一点的问题:我想将附件和图片结合起来。
下面是用于连接 IMAP 文件夹并对其执行操作的代码。所以我的问题是关于 javax.mail.Session 的,在这种情况下它会每秒重新创建一次(取决于 checkInbox() 的 hibern
我正尝试按照 http://www.tutorialspoint.com/java/java_sending_email.htm 上的指南发送电子邮件 Java 应用程序 当我尝试运行它时,从上面的链
我有一个包含 2 列 email 和 id 的表格。我需要找到密切相关的电子邮件。例如: john.smith12@example.com 和 john.smith12@some.subdomains
首先是一些信息: Debian 压缩 PHP 5.3.3 带有 mod_cgi 的 PHP 在这种情况下,我绝对必须使用 mail()。对于我所有的其他项目,我已经使用 SMTP 邮件。 我已将站点超
在对电子邮件主机的联系表单进行故障排除时,他们告诉我在 php 邮件功能的发件人地址中使用“-f”。 “-f”标志的作用是什么?为什么它可以解决允许发送电子邮件的问题?我阅读了一些文档,但不是很清楚。
一个简单的问题:群发邮件哪个性能好? mail() 函数或sendmail 流行的 PHP 列表管理器包使用哪个? 最佳答案 嗯,mail() 函数并不适合批量发送电子邮件,因为它会为您发送的每封
我正在制作一个 PHP 表单,允许用户上传附件并将其发送到我的电子邮件。我一直在寻找很长一段时间才能做到。最后,我找到了这个。 http://www.shotdev.com/php/php-mail/
我是一名优秀的程序员,十分优秀!