通过out.php发送邮件以跟踪按钮的点击次数

I need to track a button every time someone clicks on it. I created a file "out.php" to send me an email and redirect to a link outside my page. This code redirects but the mail doesn't send.

<div class="buyprod">
<a target="_blank" href="http://xxx.com/out.php?url=<?php echo urlencode($this->product['from'])?>">
<img src="http://xxx.com/buybtn.jpg" alt="buy"/>
</a>
</div>  

out.php

<?php
$url = urldecode($_GET['url']);
header("Location: ".$url);
$message = "Someone clicked buy: ";
$link = $this->product['from'];
mail('xxx@xxx.com', '@Buy', $message.$link);
exit;

Anyone knows what's wrong with this code? Thanks in advance!

You are calling a class $this->product['from'] that does not exist in out.php. This will make your file error out. Also, you need to set a 'From:' header when using mail(). see stackoverflow.com/questions/6988051/php-mail-function-headers#6988085

Change out.php to -

<?php
$url = urldecode($_GET['url']);
$message = "Someone clicked buy: ";
$link = $_GET['url'];
mail('xxx@xxx.com', '@Buy', $message.$link, 'From: email@website.com');
header("Location: ".$url);
exit;
?>

Move header() to the end, right before exit

Also, your mail function should follow the following format:

mail($to, $subject, $message, $headers);

You're calling $this->product['from'] which does doesn't exist in your out.php