0

I am trying to make a pseudo-newsletter type plugin which will email that authors of certain posts. The email sends the contents of a textarea with some extra text added to the end of it. I've sent the content type of the mail function to text/html and when I put some <a href=""></a> links the links show up correctly but they come out as dead links. Clicking them does nothing and trying to copy the link and paste it in my browser leaves me with some strange text which I will paste below along with my code.

UPDATE

I have included an a href link in the $new_message variable in the Email Users Function below and that link works correctly. So the problem seems to come when grabbing the link from the content of the textarea.

Copy Link Location

x-webdoc://46FD60D5-DD4C-4546-A811-81417B5F9A3C/%22http://bourbontrailtours.com.mm-dev.net/%22

Form

function bracket_challenge_draw_email_page() {
        if( isset( $_POST['round_submit'] ) ) {
            if( isset( $_POST['email_message'] ) ) {
                bracket_challenge_email_users( $_POST['email_message'] );
            } else {
                bracket_challenge_email_users('');
            }
        }
    ?>
        <div class="wrap">
            <h2>Round Completed Emails</h2>
            <br />
            <br />
            <form method="post" action="">
                <textarea name="email_message" id="email_message" value="" placeholder="Custom Email Message" cols="75" rows="15"></textarea>
                <?php submit_button('Send Emails', 'primary', 'round_submit'); ?>
            </form>
        </div>
    <?php
    }

Email Users Function

function bracket_challenge_email_users($message) {

        // $leaderboard = get_posts($args);

        for( $i = 0; $i < count($leaderboard); $i++ ) {

            $new_message = $message."\r\n\r\n";
            // This link works correctly so the problem is with the textarea
            $new_message .= "Congratulations your position in the <a href='".site_url()."'>leaderboard</a> after the most recent round is: ";

            $user = get_userdata( $leaderboard[$i]->post_author );
            $position = $i + 1;
            $new_message .= $position;

            add_filter('wp_mail_content_type', 'set_html_content_type');

            wp_mail( $user->user_email, 'Bracket Challenge Round Complete', $new_message, 'From: Bracket Challenge 2015 Test <email@example.com>');

            remove_filter('wp_mail_content_type', 'set_html_content_type');

        }

    }
  • so your mail is badly formatted, why is it a wordpress specific thing? It is very unlikely your issue has anything to do with the way your code sends the email – Mark Kaplun Feb 27 '15 at 14:02
  • @MarkKaplun I just updated the problem with more information. The links now work if I do them in the function, they just don't seem to work when I'm grabbing them from the POST content of a textarea. – CaldwellYSR Feb 27 '15 at 14:05
  • It is very bad idea to do not sanitize input from a user before doing anything with it. Why do you expect the user to write proper html? The user inputs a text so why do you even try to send it as HTML? – Mark Kaplun Feb 27 '15 at 14:17
  • Under this circumstance I am going to be the one sending the emails and I'm just trying to make that email send through a form rather than typing the code each time. This isn't a production plugin that I plan on using with clients, just a quick thing for me. Unfortunately it seems to not be that quick. – CaldwellYSR Feb 27 '15 at 14:28
  • 1
    sending valid html emails that will be displayed properly on all major clients is not as trivial as one might suppose it should be. – Mark Kaplun Feb 27 '15 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.