• Resolved mddsharp

    (@mddsharp)


    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 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)
  • 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 3 years, 10 months ago by tugbucket. Reason: typo
    Thread Starter mddsharp

    (@mddsharp)

    @tugbucket Copying and pasting the above code cause a WordPress critical error.

    There was a red X in the editor for $body

    @mddsharp edited my response

    Thread Starter mddsharp

    (@mddsharp)

    @tugbucket Very awesome, the edit worked! Thank you so much!!

    • This reply was modified 3 years, 10 months ago by mddsharp.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Need help with a simple script’ is closed to new replies.