Paypal IPN Help. Sending file attachments through email

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Oct 23, 2017 4:47 pm

Mon Oct 23, 2017 4:58 pm

I don't know much about PHP. I hired a freelancer to create this for me and then after I noticed an issue, his account was closed on So I'm no longer able to communicate with him. So any help is greatly appreciate. He created a system for me that automatically emails digital files to an eBay customer. It used the quantity and price information from PayPal IPN to do this. All of my digital files are one time use. So once a file is purchased on eBay, it gets emailed to the customer and then discarded. The system works great when a customer orders a quantity of 1.

The issue is when the customer orders more than 1. 2 scenarios happen: For example if a customer orders 2 digital files, lets says "XB1.pdf" and "XB2.pdf". Scenario 1 they will get "XB1.pdf" in an email and sometimes get "XB2.pdf" in a second email, but the email is filled with a bunch of giberish (I posted the email contents to the bottom of the ipn.php contents below). Scenario 2 sometimes they will get 2 emails but both contain "XB1.pdf" only and not "XB2.pdf". Can you look at the code and see if you can spot the issue? This is the ipn.php file contents and i believe this is where the issue is. contents
<?php namespace Listener;


// Set this to true to use the sandbox endpoint during testing:
$enable_sandbox = true;

// Set this to true to send a confirmation email:
$send_confirmation_email = true;

use PaypalIPN;
$ipn = new PaypalIPN();
if ($enable_sandbox) {
$verified = $ipn->verifyIPN();
$data_text = "";
foreach ($_POST as $key => $value) {
$data_text .= $key . " = " . $value . "\r\n";
if($key == "quantity"){
if($key == "mc_gross"){
if($key == "payer_email"){
if($key == "payment_status"){

mail("", "sub", $data_text);

if ($send_confirmation_email) {
// Send confirmation email

mail("", "total_payment", $total_payment);

$sql_s = "select * from settings";
$result_s = $conn->query($sql_s);
if ($result_s->num_rows > 0) {
while($query2_s = $result_s->fetch_assoc()) {


mail("", "no_of_items", $no_of_items);

$sql = "SELECT * FROM coupons where price='$total_payment' AND status=0 OR status=2 LIMIT ".$no_of_items."";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {

if($status == 0 || $status == 2){
//$fileatt = "files/".$file;
mail("", "file", $file);

$fileatt_type = "application/pdf";
$email_to = $payer_email;
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
//"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" . "--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($email_toa != ""){
$oka = @mail($email_toa, $email_subject, $email_message, $headers);

if($status == 0){
$sql = "UPDATE coupons SET status='1',sent_to='$payer_email' WHERE id='$id'";
if ($conn->query($sql) === TRUE) {}
}else if($status == 2){
if($row['sent_to'] != ""){
$sql = "UPDATE coupons SET sent_to='$payer_email' WHERE id='$id'";
if ($conn->query($sql) === TRUE) {}


}}}else {
$oka = @mail($mail_me, "No File Found", "HI,<br>".$payer_email." has made a payment of ".$total_payment." but coupon could not be found.");



// Reply with an empty 200 response to indicate to paypal the IPN was received correctly
header("HTTP/1.1 200 OK");
trash email contents, this is only a portion of it since it is very long
Write anything you want here. This will be the body of the email that is sent. This is a multi-part message in MIME format. --==Multipart_Boundary_xad2df9824fad4231989b39a4240b752ex Content-Type:text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Write anything you want here. This will be the body of the email that is sent. --==Multipart_Boundary_xad2df9824fad4231989b39a4240b752ex Content-Type: application/pdf; name="566222_XL-48Hour_3.pdf" Content-Disposition: attachment; filename="566222_XL-48Hour_3.pdf" JVBERi0xLjUNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIvTGFu Zyhlbi1VUykgL1N0cnVjdFRyZWVSb290IDEyIDAgUi9NYXJrSW5mbzw8L01hcmtlZCB0cnVlPj4+ Pg0KZW5kb2JqDQoyIDAgb2JqDQo8PC9UeXBlL1BhZ2VzL0NvdW50IDEvS2lkc1sgMyAwIFJdID4+ DQplbmRvYmoNCjMgMCBvYmoNCjw8L1R5cGUvUGFnZS9QYXJlbnQgMiAwIFIvUmVzb3VyY2VzPDwv Rm9udDw8L0YxIDUgMCBSL0YyIDkgMCBSPj4vRXh0R1N0YXRlPDwvR1M3IDcgMCBSL0dTOCA4IDAg Uj4+L1Byb2NTZXRbL1BERi9UZXh0L0ltYWdlQi9JbWFnZUMvSW1hZ2VJXSA+Pi9NZWRpYUJveFsg MCAwIDYxMiA3OTJdIC9Db250ZW50cyA0IDAgUi9Hcm91cDw8L1R5cGUvR3JvdXAvUy9UcmFuc3Bh cmVuY3kvQ1MvRGV2aWNlUkdCPj4vVGFicy9TL1N0cnVjdFBhcmVudHMgMD4+DQplbmRvYmoNCjQg MCBvYmoNCjw8L0ZpbHRlci9GbGF0ZURlY29kZS9MZW5ndGggMTc1Nz4+DQpzdHJlYW0NCniclVht b5tIEP4eKf9h++UEp8uGXXYXqKpKbdKmOTXXKPFVkar7QGzsoNjGApzU//5mBkjA9bprVW0NzM7r

New php-forum User
New php-forum User
Posts: 24
Joined: Sat Dec 02, 2017 3:12 pm

Sun Dec 03, 2017 9:29 am

When you hire someone, always get as many ways to contact them as possible. I know someone who had to hire a private investigator to find the designer that created his company's branding. He had lost all his files. The company the designer used to work for had lost all their files too. The only hope was finding the original designer and hoping he still had the original design files.

Post Reply