M
M
m4f12019-11-03 11:36:46
PHP
m4f1, 2019-11-03 11:36:46

How to send a file upon successful payment?

There is a YandexMoney form, payment is made from it and the event script writes a file that contains the datetime email and the amount. How to correctly send a specific file after payment through the Yandex form?
The form:

<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>

Event file with entry:
$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 );

?>

Log file:
2019-10-26T22:16:07Z Through Poison in the amount of 2.94 Login Order number

Sending emails via 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!
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadim Zakirov, 2019-11-03
@m4f1

Actually what is the problem? Together with file_put_contents(), call the function to send the file by passing the necessary data to it, of course, you need to write it first, but you only need a couple of lines of code there. Only instead of phpmailer I would recommend SendMailSmtpClass - the examples there are nowhere clearer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question