0

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!

Chris Fadu Uba
  • 133
  • 1
  • 1
  • 10

3 Answers3

1

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;
?>
Community
  • 1
  • 1
Sean
  • 12,443
  • 3
  • 29
  • 47
0

Move header() to the end, right before exit

Also, your mail function should follow the following format:

mail($to, $subject, $message, $headers);
Paul Dessert
  • 6,363
  • 8
  • 47
  • 74
0

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

Lateral
  • 3
  • 3