Kirim Email dengan liblary Swift Mailer


Swift Mailer dapat dihubungan dengan aplikasi PHP 5. Dengan menggunakan konsep OOP (object-oriented programming) yang diusungnya membuat liblary ini semakin baik.

Untuk mendownload liblary Swift Mailer disini http://swiftmailer.org/

contoh penggunaannya dapat dilihat seperti dibawah ini :

<?php
require_once ‘/path/Swift-5.0.3/lib/swift_required.php’;

// Create the Transport
$transport = Swift_SmtpTransport::newInstance();

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create the message
$message = Swift_Message::newInstance();

// Give the message a subject
$message->setSubject(‘Judul Email’);

// Set the From address with an associative array
$message->setFrom(array(‘pengirim@gmail.com’ => ‘Nama Pengirim’));

// Set the To addresses with an associative array
$message->setTo(array(‘tujuan@gmail.com’ => ‘nama tujuan’));

$html = “Selamat anda mendapat email”;

// Give it a body
$message->setBody($html);

// Send the message
$result = $mailer->send($message);
if($result) echo “Email sended”;
else echo “Email send failed”;
?>

Moga membantu kawan!
Salam Blackphp

About blackphp

All about programming php, ajax, jquery, mysql, etc, tips n trick. Now, i'm concern in php programming with codeigniter framework n also training my design skill with photoshop or corel... wish me luck! ('o')

Posted on February 20, 2014, in PHP and tagged , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: