ttmt
ttmt

Reputation: 4984

Send email from Wordpress

What's the best way to send a email from Wordpress after a certain action.

I'm working on a site where users can submit ideas and then other users can comment on them.

I would like to send emails to a number of different addresses (moderators) when a post is made and when a comment is made.

I have this code to add the posts with an attempt to send an email that doesn't work.

<section class="submitForm">

    <h1>Submit idea</h1>

    <?php

    if(isset($_POST['new_post']) == '1'){

        $post_title = $_POST['post_title'];
        $post_content = $_POST['content'];

        $new_post = array(
            'ID' => '',
            'post-author' => $user->ID,
            'post_title' => $post_title,
            'post_content' => $post_content,
            'post_status' => 'publish'
            );

        $post_id = wp_insert_post($new_post);
        $post = get_post($post_id);
        wp_redirect($post->guid);
        exit;

        // send email notifications


        wp_mail( '[email protected]', 'New Idea', $post_content);
    }

    echo '<form method="post" action="" >';
    echo '<label for="idea_title">Idea Title</label>';
    echo '<input type="text" name="post_title" class="title">';

    $settings = array(
        'quicktags' => false,
        'textarea_name' => 'content',
        'media_buttons' => true,
        'textarea_rows' => 12,
        'tinymce' => array(
            'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
            'bullist,blockquote,|,justifyleft,justifycenter' .
            ',justifyright,justifyfull,|,link,unlink,|' .
            ',spellchecker'
            )
        );
    wp_editor( '', 'content', $settings );

    echo '<input type="hidden" name="new_post" value="1">';
    echo '<input type="submit" class="submit" value="Submit Idea">';
    ?>

</section>

Upvotes: 0

Views: 140

Answers (1)

Vigneshwaran
Vigneshwaran

Reputation: 397

You can use PHPMailer to send an email. It will works cool.

Upvotes: 1

Related Questions