Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 贝宝IPN帮助。通过电子邮件发送文件附件_Php_Email_Pdf_Paypal - Fatal编程技术网

Php 贝宝IPN帮助。通过电子邮件发送文件附件

Php 贝宝IPN帮助。通过电子邮件发送文件附件,php,email,pdf,paypal,Php,Email,Pdf,Paypal,我对PHP了解不多。我雇佣了一个自由职业者为我创建这个,然后在我注意到一个问题后,他的帐户被关闭在freeloper.com上。所以我不能再和他交流了。因此,非常感谢您的帮助。他为我创建了一个系统,可以自动将数字文件通过电子邮件发送给eBay客户。它使用贝宝IPN提供的数量和价格信息来实现这一点。我所有的数字文件都是一次性使用的。因此,一旦在易趣上购买了文件,它就会通过电子邮件发送给客户,然后被丢弃。当客户订购数量为1时,该系统工作良好 问题在于客户的订单超过1个。出现两种情况:例如,如果客户订

我对PHP了解不多。我雇佣了一个自由职业者为我创建这个,然后在我注意到一个问题后,他的帐户被关闭在freeloper.com上。所以我不能再和他交流了。因此,非常感谢您的帮助。他为我创建了一个系统,可以自动将数字文件通过电子邮件发送给eBay客户。它使用贝宝IPN提供的数量和价格信息来实现这一点。我所有的数字文件都是一次性使用的。因此,一旦在易趣上购买了文件,它就会通过电子邮件发送给客户,然后被丢弃。当客户订购数量为1时,该系统工作良好

问题在于客户的订单超过1个。出现两种情况:例如,如果客户订购2个数字文件,则显示“XB1.pdf”和“XB2.pdf”。场景1他们会在一封电子邮件中看到“XB1.pdf”,有时会在第二封电子邮件中看到“XB2.pdf”,但电子邮件中充满了一串胡言乱语(我将电子邮件内容发布在下面的ipn.php内容的底部)。场景2有时他们会收到两封电子邮件,但都只包含“XB1.pdf”,而不包含“XB2.pdf”。你能看看代码,看看是否能发现问题吗?这是ipn.php文件的内容,我相信这就是问题所在

ipn.ph含量

<?php namespace Listener;

include('config.php');

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




require('PaypalIPN.php');
use PaypalIPN;
$ipn = new PaypalIPN();
if ($enable_sandbox) {
    $ipn->useSandbox();
}
$verified = $ipn->verifyIPN();
$no_of_items=1;
$data_text = "";
foreach ($_POST as $key => $value) {
    $data_text .= $key . " = " . $value . "\r\n";
    if($key == "quantity"){
    $no_of_items=$value;
    }
    if($key == "payment_gross"){
    $total_payment=$value;  
    }
    if($key == "payer_email"){
    $payer_email=$value;    
    }
    if($key == "payment_status"){
    $payment_status=$value; 
    }

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


if ($send_confirmation_email) {
    // Send confirmation email
$total_payment=$total_payment/$no_of_items;

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()) {

$email_from=$query2_s['email_from'];    
$email_subject=$query2_s['email_subject'];
$email_toa=$query2_s['email_to'];
$email_message=$query2_s['email_message'];
//$fileatt_name=$query2_s['fileame'];
$mail_me=$query2_s['mail_me'];  
}}

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()) {

$status=$row['status'];     
if($status == 0 || $status == 2){
$file=$row['file']; 
$fileatt_name=$file;
$id=$row['id'];     
$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));
            fclose($file);
            $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'] != ""){  
$payer_email=$row['sent_to'].",".$payer_email;
}
$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");

问题在于,代码在每个循环中都附加到
$email\u message
。第一次通过是好的;第二次,通过一组新的标题和数据被附加到原始电子邮件消息中,这会破坏内容

要更详细地查看问题,请按照代码进行操作。此行设置消息的初始内容:

$email_message = $query2_s['email_message'];
内容来自数据库,从您包含的输出中,我们可以看到:

在这里写你想写的任何东西。这将是发送的电子邮件的正文

接下来,代码选择要处理的记录,并开始对它们进行迭代。它通过向上面准备的现有内容添加一些数据来构造消息:

$email_message .= "This is a multi-part message in MIME format.\n\n"
// etc, there are several lines of headers added here
最后,使用在最后几个步骤中构造的内容发送邮件:

$ok = @mail($email_to, $email_subject, $email_message, $headers);
很好,第一封邮件的内容很好。但是,如果有多个项,代码现在将循环并再次运行,以用于下一条记录。这里有一个问题-
$email\u message
没有重置回空字符串,或者数据库中的初始“Write any you want…”消息。而是在现有邮件内容中添加第二组标题:

$email_message .= "This is a multi-part message in MIME format.\n\n"
// etc, appends new stuff to existing $email_message
$email_message
现在包括邮件1的标题和内容,邮件2的标题和内容附加到邮件1中

要避免这种情况,请使用不同的变量名。例如,代替这一行:

$email_message = $query2_s['email_message'];
使用:

而不是:

$email_message .= "This is a multi-part message in MIME format.\n\n" .
使用:


这样,
$email\u message
在每次迭代中都是从头开始创建的,使用数据库中的
$email\u前缀
,并附加msg的其余部分。

代码的格式真的是这样的吗,还是在这里发布时不知怎么搞砸了?我更新了它,现在ipn.php的内容看起来应该更好了,有几行,比如
mail(“,”total_payment“,$total_payment)-他们真的是这样吗,还是你删除了电子邮件地址?哦,对不起,是的,我临时删除了电子邮件地址。这些都是用来检查的目的,我假设。如果需要,我可以发送所有的php文件仍然有相同的问题。不过非常感谢你的帮助。我可能不得不雇佣一个自由职业者来修复前一个自由职业者的代码。或者也许我只需要学习phplol@RLane你是否也遇到了同样的问题,邮件中有垃圾,还有加倍的“想写什么就写什么…”?如果是这样的话,编辑出了问题,正如我所描述的,将解决这个问题。如果您看到其他错误,则与多个项目相关的代码中可能存在另一个问题。现在,无论发送多少封电子邮件,只发送一封包含一个文件的电子邮件。我更新了你上面提到的两行。我还从注释掉的行中删除了//。我不知道为什么程序员把它们注释掉了。现在已经修好了。非常感谢你的帮助。它现在的工作方式应该是这样的。自由撰稿人终于回复我:)
$email_message .= "This is a multi-part message in MIME format.\n\n" .
$email_message = $email_prefix . "This is a multi-part message in MIME format.\n\n" .