Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require '../phpmailer/class.phpmailer.php';
- // ------------------------------------------------
- // setting dulu php mailer nya,
- // nilai nya ndak akan berubah sepanjang script.
- // jadi ndak perlu ditaruh di dalam perulangan while.
- // cukup sekali aja setting nya.
- // ------------------------------------------------
- $mail = new PHPMailer(true);
- $mail->IsSMTP(); // tell the class to use SMTP
- $mail->SMTPAuth = true; // enable SMTP authentication
- $mail->SMTPSecure = 'tls';
- $mail->Port = 587; // set the SMTP server port
- $mail->Host = 'smtp.gmail.com'; // SMTP server
- $mail->Username = 'xxxxxx@gmail.com'; // SMTP server username
- $mail->Password = 'xxxxxxx'; // SMTP server password
- //$mail->IsSendmail(); // tell the class to use Sendmail
- $mail->AddReplyTo('xxxxx@gmail.com');
- $mail->From = 'xxxxx@gmail.com';
- $mail->FromName ='xxxxx';
- $mail->Subject = 'report sales';
- //$mail->AltBody = βTo view the message, please use an HTML compatible email viewer!β;
- //optional, comment out and test
- //$mail->WordWrap = 80; // set word wrap
- $mail->IsHTML(true); // send as HTML
- // ------------------------------------------------
- // generate body jadikan fungsi.
- // tinggal panggil.
- // tapi kalo bingung, ndak pake fungsi ya ndak apa.
- // ------------------------------------------------
- function generateBody($body='',$val=array(),$reset=0) {
- if($reset==1) {
- $body='<tr><td>No</td><td>nama</td><td>email</td><td>kegiatan</td></tr>';
- }
- else if($reset==2) {
- $body='<table border="1">'.$body.'</table>';
- }
- else {
- $body.=$body.
- '<tr><td>'.$val['no'].'</td><td>'.$val['nama'].'</td><td>'.$val['email'].'</td><td>'.$val['kegiatan'].'</td></tr>';
- }
- return $body;
- }
- // ------------------------------------------------
- $send=false;
- $i=1;
- $email='';
- $body='';
- $body=generateBody($body,array(),1); // reset $body, isi cuma header table
- while($row_spc=mysql_fetch_assoc($spc)) {
- if($email!=$row_spc['email']) {
- if($i!=1) {
- $body=generateBody($body,array(),2); // tutup $body table
- $mail->AddAddress($email); // set alamat email tujuan
- $mail->MsgHTML($body); // set isi email
- $mail->Send(); // kirim email
- $send=true;
- echo $body.'<br>';
- echo 'Message has been sent to : '.$email.'<br>';
- $body=generateBody($body,array(),1); // reset $body, isi cuma header table
- }
- $row_spc['no']=$i;
- $body=generateBody($body,$row_spc); // isi $body dengan data lengkap
- $send=false;
- $email=$row_spc['email'];
- $i++;
- }
- else {
- $row_spc['no']='';
- $row_spc['nama']='';
- $row_spc['email']='';
- $body=generateBody($body,$row_spc); // isi $body dengan hanya data kegiatan
- $send=false;
- }
- }
- if(!$send) { // periksa ada pesan terakhir yg belum dikirim
- $body=generateBody($body,array(),2); // tutup $body table
- $mail->AddAddress($email); // set alamat email tujuan
- $mail->MsgHTML($body); // set isi email
- $mail->Send(); // kirim email
- echo $body.'<br>';
- echo 'Message has been sent to : '.$email.'<br>';
- }
- ?>
- </p>
- <p> </p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement