0

好的,我会切入正题,我有这段代码会产生一个随机字符串:

function random_string()
{      
    $character_set_array = array();

    //$character_set_array[] = array('count' => 2, 'characters' => 'AA');
    $character_set_array[] = array('count' => 8, 'characters' => '0123456789');
    $temp_array = array();
    foreach ($character_set_array as $character_set) {
        for ($i = 0; $i < $character_set['count']; $i++) {
            $temp_array[] = $character_set['characters'][rand(0, strlen($character_set['characters']) - 1)];
        }
    }
    shuffle($temp_array);
    $pinstart = 'AA';
    $pinend = implode('', $temp_array);
    $pin = $pinstart.$pinend;
    echo $pin;
}

然后在我的贝宝 IPN 我有这个:

if($p->ipn_data["mc_gross"] > 0 && strcmp ($p->ipn_data["business"],$EMAIL) == 0 && ($p->ipn_data["item_number"]) == 1)  {
         $user = $p->ipn_data["custom"];
             $date = $p->ipn_data["payment_date"];
             $prodid = $p->ipn_data["item_number"];
             $amount = $p->ipn_data["mc_gross"];
             $amountTickets = 1;
             $email = 'email@hotmail.com';
             $subject = '[CODE] - Thank you for your donation';
             $message = 'Your CODE IS, <? echo random_string(); ?>';
             mail("$payer_email", "$subject",
             $message.random_string(), "From: $email" );
             $user = str_replace("_", " ", $user);
             $user = str_replace("-", " ", $user);
             $user = mysql_real_escape_string($user);

         }

它发送电子邮件,但它的“您的代码是,,它不会发布随机字符串。

我试过把 $pin, $pin = random_string(); 打印 $pin 没有任何作用

4

2 回答 2

0

在您的函数中更改echo $pin;为,因为您希望它返回一个字符串,而不是当场打印出一个字符串,然后return $pinrandom_string

$message = 'Your CODE IS, ' . random_string();
于 2013-08-08T02:11:51.687 回答
0

random_string 应该使用 return 而不是 echo

然后

...
 $subject = '[CODE] - Thank you for your donation';
  $message = 'Your CODE IS,'. random_string();
  mail("$payer_email", "$subject",
...
于 2013-08-08T02:13:54.593 回答