希望一些PHP大师可以帮助我解决这个问题。我正在创建一个简单的捐赠表单来接受使用Stripe的付款。我在这里包含了我的代码。表格在处理付款方面表现良好。但是,该脚本应该向捐赠者发送一封确认电子邮件,说他们的捐款已经收到,等等。我遇到的问题是脚本没有发送这样的确认。我正在使用GoDaddy托管并检查我的MX记录是否正确。我从我的托管帐户运行测试(在GoDaddy支持的帮助下)以及查看帐户本身是否存在任何问题。测试显示没有这样的问题。我尝试了一些小调整,例如更改标题,添加<>等等,但没有运气。
这是我的config.php代码
<?php
return array(
'test-mode' => true,
'secret-key' => 'YOUR_SECRET_KEY',
'publishable-key' => 'YOUR_PUBLISHABLE_KEY',
'thank-you' => 'http://example.com/thank-you.html',
'email-from' => 'no-reply@example.com',
'email-bcc' => 'admin@example.com',
'email-subject' => 'Thank you for your donation!',
'email-message' => "Dear %name%,\n\nThank you for your order of %amount%."
);
这是我的index.php代码
<?php
require('lib/Stripe.php');
$config = require('config.php');
if ($config['test-mode'] && $_SERVER['HTTPS'] != 'on') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit;
}
if ($_POST) {
Stripe::setApiKey($config['secret-key']);
$token = $_POST['stripeToken'];
$first_name = $_POST['first-name'];
$last_name = $_POST['last-name'];
$name = $first_name . ' ' . $last_name;
$address = $_POST['address'] . "\n" . $_POST['city'] . ', ' . $_POST['state'] . ' ' . $_POST['zip'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$amount = (float) $_POST['amount'];
try {
if ( ! isset($_POST['stripeToken']) ) {
throw new Exception("The Stripe Token was not generated correctly");
}
// Charge the card
$donation = Stripe_Charge::create(array(
'card' => $token,
'description' => 'Donation by ' . $name . ' (' . $email . ')',
'amount' => $amount * 100,
'currency' => 'usd'
));
// Build and send the email
$headers = 'From: ' . $config['emaily-from'];
$headers .= "\r\nBcc: " . $config['emaily-bcc'] . "\r\n\r\n";
// Find and replace values
$find = array('%name%', '%amount%');
$replace = array($name, '$' . $amount);
$message = str_replace($find, $replace , $config['email-message']) . "\n\n";
$message .= 'Amount: $' . $amount . "\n";
$message .= 'Address: ' . $address . "\n";
$message .= 'Phone: ' . $phone . "\n";
$message .= 'Email: ' . $email . "\n";
$message .= 'Date: ' . date('M j, Y, g:ia', $donation['created']) . "\n";
$message .= 'Transaction ID: ' . $donation['id'] . "\n\n\n";
$subject = $config['email-subject'];
// Send it
if ( !$config['test-mode'] ) {
mail($email,$subject,$message,$headers);
}
// Forward to "Thank You" page
header('Location: ' . $config['thank-you']);
exit;
} catch (Exception $e) {
$error = $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Stripe Payment Form</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all">
<script type="text/javascript" src="https://js.stripe.com/v2"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
Stripe.setPublishableKey('<?php echo $config['publishable-key'] ?>');
</script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div class="wrapper">
<h1>Stripe Payment Form</h1>
<p><strong>Thanks for donating!</strong></p>
<div class="messages">
<!-- Error messages go here go here -->
</div>
<form action="#" method="POST" class="donation-form">
<fieldset>
<legend>
Contact Information
</legend>
<div class="form-row form-first-name">
<label>First Name</label>
<input type="text" name="first-name" class="first-name text">
</div>
<div class="form-row form-last-name">
<label>Last Name</label>
<input type="text" name="last-name" class="last-name text">
</div>
<div class="form-row form-email">
<label>Email</label>
<input type="text" name="email" class="email text">
</div>
<div class="form-row form-phone">
<label>Phone</label>
<input type="text" name="phone" class="phone text">
</div>
<div class="form-row form-address">
<label>Address</label>
<textarea name="address" cols="30" rows="2" class="address text"></textarea>
</div>
<div class="form-row form-city">
<label>City</label>
<input type="text" name="city" class="city text">
</div>
<div class="form-row form-state">
<label>State</label>
<select name="state" class="state text">
<option value="AL">AL</option>
<option value="WY">WY</option>
</select>
</div>
<div class="form-row form-zip">
<label>Zip</label>
<input type="text" name="zip" class="zip text">
</div>
</fieldset>
<fieldset>
<legend>
Your Generous Donation
</legend>
<div class="form-row form-amount">
<label><input type="radio" name="amount" class="set- amount" value="25"> $25</label>
<label><input type="radio" name="amount" class="set-amount" value="100"> $100</label>
<label><input type="radio" name="amount" class="other-amount" value="0"> Other:</label> <input type="text" class="amount text" disabled>
</div>
<div class="form-row form-number">
<label>Card Number</label>
<input type="text" autocomplete="off" class="card-number text" value="4242424242424242">
</div>
<div class="form-row form-cvc">
<label>CVC</label>
<input type="text" autocomplete="off" class="card-cvc text" value="123">
</div>
<div class="form-row form-expiry">
<label>Expiration Date</label>
<select class="card-expiry-month text">
<option value="01" selected>January</option>
<option value="12">December</option>
</select>
<select class="card-expiry-year text">
<option value="2017" selected>2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
</select>
</div>
<div class="form-row form-submit">
<input type="submit" class="submit-button" value="Submit Donation">
</div>
</fieldset>
</form>
</div>
<script>if (window.Stripe) $('.donation-form').show()</script>
<noscript><p>JavaScript is required for the donation form.</p></noscript>
</body>
</html>
非常感谢任何帮助。