edit: thanks for the advice all but I was looking for the actual code. Just hired someone on fiverr to write it. the curl and other extraneous code was from previous attempts.
Hey all. I don't know much about php but have been trying to get this api script working. This is the callback script which is supposed to send two letters after bitcoin has been sent with one confirmation: one to me and one to the customer. I am having a hard time getting this to send an email after just one confirmation. If I take this part out: "if ($_GET['confirmations'] == 1)" then it will send me emails every hour with different confirmation amounts. But if I put this qualifier in it sends me nothing. I am guessing that maybe when the script is kicks in the number of confirmations might be over 1 already? How do I solve this to get the script to send just one email after one confirmation? First person to reply with fix and their wallet address gets reward.
/**
* Callback endpoint for the Blockchain Receive API.
*
* Notifies the administrator when a watched address has a new transaction.
*/
if ($_GET['confirmations'] < 1) {
die('Waiting for 1 notification.');
}
$to = '
[email protected]';
$subject = 'New transaction through Blockchain API';
$message = 'There is a new transaction detected by the Blockchain API.' . "\r\n\r\n";
$message .= 'Amount: ' . sprintf('%02.8f', ($_GET['value'] / 100000000)) . ' BTC'. "\r\n";
$message .= 'Address: ' . $_GET['input_address'] . "\r\n";
$message .= 'Confirmations: ' . $_GET['confirmations'] . "\r\n";
$message .= 'Track:
http://blockchain.info/tx/' . $_GET['transaction_hash'] . "\r\n";
$message .= 'Customer\'s email: ' . $_GET['email'] . "\r\n";
$headers = 'From: "Blockchain API endpoint" <
[email protected]>';
$fields = array(
'to' => $to,
'subject' => $subject,
'message' => $message,
'headers' => $headers,
);
$postvars = http_build_query($fields);
if ($_GET['confirmations'] == 1) {
mail($to, $subject, $message, $headers);
}
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$res = curl_exec($ch);
if ($res == 'ok') {
echo '*ok*';
}
else {
echo 'Mail not sent!';
echo $res;
}
if (isset($_GET['email'])) {
$to = $_GET['email'];
$subject = 'Payment Verification';
$message = 'This is an automatic notification that I have received a payment for your order.' . "\r\n\r\n";
$message .= 'Your item should arrive in the mail within a week.';
$headers = 'From: "Marley" <
[email protected]>';
$fields = array(
'to' => $to,
'subject' => $subject,
'message' => $message,
'headers' => $headers,
);
$postvars = http_build_query($fields);
if ($_GET['confirmations'] == 1) {
mail($to, $subject, $message, $headers);
}
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$res = curl_exec($ch);
}