Email Blast in Custom Module

Hello,

i have create a custom module just like in attachment 1 using studio.

i want to ask how i can send mail with that module?

‘pop’ is the condition in Accounts module.

can i combine with my custom php?

this is the code of my custom php

<?php

require_once "swiftmailer/lib/swift_required.php";
mysql_connect("localhost", "root", "") or die ("Gagal Konek ke Server");
mysql_select_db("test") or die ("DB not found");
echo 'Connected successfully';

if(isset($_POST['send']))
{
$subject = $_POST['subject'];
$isi = nl2br($_POST['message']);
$search=implode(',',$_POST['pop']);
$que= "AND pop_c IN ($search)";
}

$query="select email_addresses.email_address AS email, accounts_cstm.pop_c AS pop
from accounts_cstm, accounts, email_addresses, email_addr_bean_rel
where
accounts.id = accounts_cstm.id_c and
accounts.id = email_addr_bean_rel.bean_id and
email_addr_bean_rel.email_address_id = email_addresses.id
and accounts_cstm.status_c = 'Aktif' $que";
$result=mysql_query("$query");

$mailer = Swift_Mailer::newInstance( Swift_SmtpTransport::newInstance('103.10.98.142', 25));

$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(50, 20));

while($row = mysql_fetch_array($result)){

$from = array('noc.bali@mail.net.id' =>'NOC ');
$to = array     (
        $row['email']  => $row['email'] //$email
                );


$html = $isi.'<br><br>
some text here
<br>



$transport = Swift_SmtpTransport::newInstance('103.10.98.142', 25);
$swift = Swift_Mailer::newInstance($transport);

$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);

$failedRecipients=array();
$numSent=0;
foreach ($to as $address=>$name){
        if(is_int($address)){
        $message->setTo($name);
        }else{
        $message->setTo(array($address=>$name));
        }
        $numSent+=$mailer->send($message,$failedRecipients);
}

printf("send %d messages \n",$numSent);
}

?>

thanks

http://developer.sugarcrm.com/2011/03/01/howto-send-an-email-inside-sugar-thru-code/

http://developer.sugarcrm.com/2011/08/15/howto-send-and-archive-an-email-in-sugar-via-php/

1 Like

Hi Andy,

Thanks for your advice.

but its can send email to 1000++ email address? or like mass mail?

thankyou