Title: Need help with a simple script
Last modified: January 3, 2021

---

# Need help with a simple script

 *  Resolved [mddsharp](https://wordpress.org/support/users/mddsharp/)
 * (@mddsharp)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/need-help-with-a-simple-script/)
 * I have the following in my theme functions.php file:
 *     ```
       function wpse113069_email_me_every_visit() {
           wp_mail( 'me@example.net', 'You had a visitor...', 'Yea, someone was on your site!' );
       }
   
       add_action( 'wp', 'wpse113069_email_me_every_visit' );
       ```
   
 * This simply emails [me@example.net](https://wordpress.org/support/topic/need-help-with-a-simple-script/me@example.net?output_format=md)
   anytime someone visits my site with the subject “You had a visitor…” and email
   body “Yea, someone was on your site!”.
 * What would I add to this such that the post URLs are included in the email?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [tugbucket](https://wordpress.org/support/users/tugbucket/)
 * (@tugbucket)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/need-help-with-a-simple-script/#post-13858463)
 * try:
 *     ```
       function wpse113069_email_me_every_visit() {
       	$url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
       	$body = 'Yea, someone was on your site! They visited: '.$url;
           wp_mail( 'me@example.net', 'You had a visitor...', $body );
       }
   
       add_action( 'wp', 'wpse113069_email_me_every_visit' );
       ```
   
    -  This reply was modified 5 years, 5 months ago by [tugbucket](https://wordpress.org/support/users/tugbucket/).
      Reason: typo
 *  Thread Starter [mddsharp](https://wordpress.org/support/users/mddsharp/)
 * (@mddsharp)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/need-help-with-a-simple-script/#post-13858476)
 * [@tugbucket](https://wordpress.org/support/users/tugbucket/) Copying and pasting
   the above code cause a WordPress critical error.
 * There was a red X in the editor for $body
 *  [tugbucket](https://wordpress.org/support/users/tugbucket/)
 * (@tugbucket)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/need-help-with-a-simple-script/#post-13858478)
 * [@mddsharp](https://wordpress.org/support/users/mddsharp/) edited my response
 *  Thread Starter [mddsharp](https://wordpress.org/support/users/mddsharp/)
 * (@mddsharp)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/need-help-with-a-simple-script/#post-13858505)
 * [@tugbucket](https://wordpress.org/support/users/tugbucket/) Very awesome, the
   edit worked! Thank you so much!!
    -  This reply was modified 5 years, 5 months ago by [mddsharp](https://wordpress.org/support/users/mddsharp/).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Need help with a simple script’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [mddsharp](https://wordpress.org/support/users/mddsharp/)
 * Last activity: [5 years, 5 months ago](https://wordpress.org/support/topic/need-help-with-a-simple-script/#post-13858505)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
