How to send an email notification when a page is visited?

前端 未结 3 701
野性不改
野性不改 2020-12-20 02:53

Is there a way to send an email notification if a certain page is visited?
(Triggers an email saying the page was viewed)

Ie. User comes to this page: t

相关标签:
3条回答
  • 2020-12-20 03:27

    Try:

    <?php
    // The message
    $message = "Line 1\nLine 2\nLine 3";
    
    // In case any of our lines are larger than 70 characters, we should use wordwrap()
    $message = wordwrap($message, 70);
    
    // Send
    mail('admin@example.com', 'My Subject', $message);
    
    // Redirect
    header('Location: anotherpage.php');
    ?>
    
    0 讨论(0)
  • 2020-12-20 03:27

    Yes. Just use this at any place in your page: PHP Mail

    0 讨论(0)
  • 2020-12-20 03:32

    Yes, the mail function.

    But I think you should reconsider this design - imagine what will happen if the page suddently gets hit by thousands upon thousands of users - or a buggy web crawler. A log file or database update is alot easier to handle.

    0 讨论(0)
提交回复
热议问题