douguxun6866 2012-11-21 18:15
浏览 72
已采纳

通过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!

  • 写回答

3条回答 默认 最新

  • dongtan9518 2012-11-21 18:49
    关注

    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;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?