@m4f1

Как сделать отправку файла при успешной оплате?

Существует форма YandexMoney, с нее производится оплата и скрипт события пишет файл, в котором указаны datetime email и сумма. Как правильно сделать отправку определенного файла после оплаты через Яндекс форму?
Форма:
<form method="POST" action="https://money.yandex.ru/quickpay/confirm.xml">    
<input type="hidden" name="receiver" value="номер кошелька">    

<input type="text" name="label" value="$email_buyer" placeholder="Ваш e-mail адрес">  
<input type="text" name="sum" value="$_price" data-type="number"> 
<input type="hidden" name="successURL" value="./success.php">

<input type="hidden" name="formcomment" value="длинное описание">    
<input type="hidden" name="short-dest" value="короткое описание">    
<input type="hidden" name="quickpay-form" value="shop">    
<input type="hidden" name="targets" value="Оплата">    
<input type="hidden" name="need-fio" value="false">    
<input type="hidden" name="need-email" value="true">    
<input type="hidden" name="need-phone" value="false">    
<input type="hidden" name="need-address" value="false">    
<label><input type="radio" name="paymentType" value="PC">Яндекс.Деньгами</label>    
<label><input type="radio" name="paymentType" value="AC">Банковской картой</label>    
<input type="submit" value="Перевести">
</form>


Файл события с записью:
$hash = sha1($_POST['notification_type'].'&'.
$_POST['operation_id'].'&'.
$_POST['amount'].'&'.
$_POST['currency'].'&'.
$_POST['datetime'].'&'.
$_POST['sender'].'&'.
$_POST['codepro'].'&'.
'тут секретный ключ'.'&'.
$_POST['label']);

if ( $_POST['sha1_hash'] != $hash or $_POST['codepro'] === true or $_POST['unaccepted'] === true ) exit('error');

file_put_contents('history.php', $_POST['datetime'] . ' Через ЯД на сумму ' . $_POST['amount'] . ' Логин ' . $_POST['label'] . PHP_EOL, FILE_APPEND );

?>


Файл логов:
2019-10-26T22:16:07Z Через ЯД на сумму 2.94 Логин Номер заказа


Письма отправляю через SMTP php-mailer
<?php

require_once('./class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

$mail->IsSMTP(); // telling the class to use SMTP

try {
  $mail->Host       = ""; // SMTP server
  $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->Host       = ""; // sets the SMTP server
  $mail->Port       = 587;                    // set the SMTP port for the GMAIL server
  $mail->Username   = ""; // SMTP account username
  $mail->Password   = "";        // SMTP account password
  $mail->AddReplyTo('', 'First Last');
  $mail->AddAddress('', 'John Doe');
  $mail->SetFrom('', 'От доброжелателя');
  $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  $mail->MsgHTML(file_get_contents('contents.html'));
  $mail->AddAttachment('file');      // attachment
  $mail->Send();
  echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}
?>
  • Вопрос задан
  • 637 просмотров
Решения вопроса 1
@zkrvndm
Софт для автоматизации
Собственно в чем проблема? Вместе с file_put_contents() вызывайте функцию для отправки файла передав в нее нужные данные, конечно ее сначала написать надо, но там всего пару строк кода нужно. Только вместо phpmailer я рекомендовал бы SendMailSmtpClass - примеры там нагляднее некуда.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы