我使用的是PHP,除了使用任何代码或其他方式从仪表板手动发送付款以外,是否可以在Stripe for TEST ACCOUNT中成功付款后发送电子邮件?
EDIT1:我已将phpmailer代码添加到我的文件中,并说已发送了电子邮件,但未收到任何电子邮件。我在另一个页面的联系表单中尝试过它,但是可以正常工作,但是当我将其添加到有条纹(有一些更改)的文件中时,它不起作用。这是thankYou.php中的代码:
<?php
require_once 'core/init.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/Exception.php';
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
if(isset($_POST['submit_2'])) {
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->addAddress($_POST['email']);
$mail->Username = "myemail";
$mail->Password = "mypassword";
$mail->IsHTML(true);
$mail->SingleTo = true;
$mail->From = "myemail";
$mail->Subject = "Stripe";
$mail->Body = "Test";
if(!$mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
} else {
echo "Email sent";
}
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey(STRIPE_PRIVATE);
// Get the credit card details submitted by the form
$token = isset($_POST['stripeToken'])? $_POST['stripeToken']:'';
// Get the rest of the post data
$full_name = isset($_POST['full_name'])? sanitize($_POST['full_name']):'';
$email = isset($_POST['email'])? sanitize($_POST['email']):'';
$street = isset($_POST['street'])? sanitize($_POST['street']):'';
$street2 = isset($_POST['street2'])? sanitize($_POST['street2']):'';
$city = isset($_POST['city'])? sanitize($_POST['city']):'';
$state = isset($_POST['state'])? sanitize($_POST['state']):'';
$phone_number = isset($_POST['phone_number'])? sanitize($_POST['phone_number']):'';
$country = isset($_POST['country'])? sanitize($_POST['country']):'';
$tax = isset($_POST['tax'])? sanitize($_POST['tax']):'';
$sub_total = isset($_POST['sub_total'])? sanitize($_POST['sub_total']):'';
$grand_total = isset($_POST['grand_total'])? sanitize($_POST['grand_total']):'';
$cart_id = isset($_POST['cart_id'])? sanitize($_POST['cart_id']):'';
$description = isset($_POST['description'])? sanitize($_POST['description']):'';
$charge_amount = number_format((float)$grand_total,2) * 100;
$metadata = array(
"cart_id" => $cart_id,
"tax" => $tax,
"sub_total" => $sub_total,
);
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = \Stripe\Charge::create(array(
"amount" => $charge_amount, // amount in cents, again
"currency" => CURRENCY,
"source" => $token,
"description" => $description,
"receipt_email" => $email,
"metadata" => $metadata)
);
//adjust inventory
$itemQ = $db->query("SELECT * FROM cart WHERE id = '{$cart_id}'");
$iresults = mysqli_fetch_assoc($itemQ);
$items = json_decode($iresults['items'],true);
foreach($items as $item){
$newAges = array();
$item_id = $item['id'];
$productQ = $db->query("SELECT ages, sold FROM products WHERE id = '{$item_id}'");
$product = mysqli_fetch_assoc($productQ);
$ages = agesToArray($product['ages']);
$soldproducts = $product['sold'];
foreach($ages as $age){
if($age['age'] == $item['age']){
$q = $age['quantity'] - $item['quantity'];
$newAges[] = array('age' => $age['age'],'quantity' => $q,'threshold' => $age['threshold']);
}else{
$newAges[] = array('age' => $age['age'],'quantity' => $age['quantity'],'threshold' => $age['threshold']);
}
}
if (isset($item['quantity'])) {
$sold = ($soldproducts + $item['quantity']);
}
$ageString = agesToString($newAges);
$db->query("UPDATE products SET ages = '{$ageString}', sold = '{$sold}' WHERE id = '{$item_id}'");
}
//update cart
$db->query("UPDATE cart SET paid = 1 WHERE id = '{$cart_id}'");
$db->query("INSERT INTO transactions
(charge_id,cart_id,full_name,email,street,street2,city,state,phone_number,country,sub_total,tax,grand_total,description,txn_type)
VALUES ('$charge->id','$cart_id','$full_name','$email','$street','$street2','$city','$state','$phone_number','$country','$sub_total',
'$tax','$grand_total','$description','$charge->object')");
$domain = ($_SERVER['HTTP_HOST'] != 'localhost')? '.'.$_SERVER['HTTP_HOST']:false;
setcookie(CART_COOKIE,'',1,"/",$domain,false);
include 'includes/head.php';
include 'includes/navigation.php';
?>
<div class="container-fluid" style="margin-top:100px;">
<h1 class="text-center text-success">Thank You!</h1>
<p> Your card has been successfully charged <?=money($grand_total);?>. You have been emailed a receipt. Please
check you spam folder if it is not in your inbox. Additionally you can print this page as a receipt.</p>
<p>Your receipt number is: <strong><?=$cart_id;?></strong></p>
<p>Your order will be shipped to the address below.</p>
<address>
<?=$full_name;?><br>
<?=$city. ', '.$state.' ';?><br>
<?=$street;?><br>
<?=$street2;?><br>
<?=$phone_number;?><br>
</address>
</div>
<?php
include 'includes/footer.php';
} catch(\Stripe\Error\Card $e) {
// The card has been declined
echo $e;
}
?>
在cart.php文件中(并非所有代码):
<div class="form-group col-lg-6">
<label for="email">Email:</label>
<input class="form-control" id="email" name="email" type="text">
</div>
<button type="submit" name="submit_2" class="btn btn-primary" id="checkout_button" style="display:none;">Check Out >></button>
请帮助...
答案 0 :(得分:1)
这来自Stripe API documentation(PHP):
receipt_email可选
此费用收据将发送到的电子邮件地址。在支付费用之前不会发送收据,也不会发送测试模式费用的收据。如果这笔费用是针对客户的,则此处指定的电子邮件地址将覆盖该客户的电子邮件地址。如果将live_mode指定为即时收款收费,则无论您的电子邮件设置如何,都会发送收据