0

How can i prevent swiftmailer sending mails to the address from which te mails are sent?

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/www/wordpress/wp-config.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/www/wordpress/wp-load.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/www/wordpress/wp-includes/wp-db.php';

global $wpdb;

$wpdb->show_errors = TRUE;
$wpdb->suppress_errors = FALSE;

$transport = Swift_SmtpTransport::newInstance('smtp.live.com', 587, 'tls')
->setAuthMode('login')
->setUsername('hotmailaddress@hotmail.com')
->setPassword('**********');

$mailer = Swift_Mailer::newInstance($transport);

$subscribers = $wpdb->get_results( 
$wpdb->prepare(

"SELECT * FROM 
            wp_nwsbrf_subscribers 
                INNER JOIN 
                    wp_nwsbrf_couple
                        INNER JOIN 
                            wp_nwsbrf_categories
                                INNER JOIN
                                    wp_posts
                                        INNER JOIN
                                            wp_nwsbrf_subscribers_categorie
                                                WHERE
                                                wp_nwsbrf_subscribers_categorie.category_id = wp_nwsbrf_categories.category_id
                                                AND
                                                wp_nwsbrf_subscribers_categorie.subscriber_id = wp_nwsbrf_subscribers.subscriber_id
                                                AND 
                                                wp_nwsbrf_couple.category_id = wp_nwsbrf_categories.category_id
                                                AND
                                                wp_posts.ID = wp_nwsbrf_couple.ID
                                                AND
                                                wp_nwsbrf_couple.ID = %d", $_GET['postid']) );

if($wpdb->num_rows == 0)
{
    echo 'Er zijn geen abonnees';
}
else
{

    $arr = array();

    foreach ($subscribers as $subscriber) {

        $arr[] = $subscriber->subscriber_mail;
        $title = $subscriber->post_title;
        $message = $subscriber->post_content;

        $message = Swift_Message::newInstance($title)
        ->setFrom( array('hotmailaddress@hotmail.com'=>'Nieuwsbrief BV') )
        ->setTo( $arr )
        ->setBody($message);

        $result = $mailer->send($message);

    }

    echo 'Verzonden naar alle aangemelde abonnees!';
    var_dump($arr);
}

  ?>

So everytime when i send an email to it's receivers, swiftmailer also sends the same email to the sender. How can i resolve this problem?

4

0 回答 0