PHP MAILER

Contoh penggunaan Fungsi mail():
<?php
$To = “support@mydomain.com”;         // email yang dituju
$Subject = ‘Contoh subyek email’;     // subyek email
$From = “From: ” . $_POST[“email”];   // header untuk mendefinisikan darimana pengirim email berasal
$Body = ‘Isi dari email’;             // isi email

mail($To, $Subject, $Body, $From);    // mengirim email
?>

Masing-masing parameter dari fungsi mail() dipisahkan dengan variabel untuk memudahkan pemahaman.
Berikut jika menggunakan phpmailer berikut attachement.

require(“class.phpmailer.php”);
$mail = new PHPMailer();
$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = “smtp1.site.com;smtp2.site.com”; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = “jswan”;  // SMTP username
$mail->Password = “secret”; // SMTP password
$mail->From     = “from@email.com”;
$mail->FromName = “Mailer”;
$mail->AddAddress(“josh@site.com”,”Josh Adams”);
$mail->AddAddress(“ellen@site.com”);               // optional name
$mail->AddReplyTo(“info@site.com”,”Information”);
$mail->WordWrap = 50;                              // set word wrap
$mail->AddAttachment(“/var/tmp/file.tar.gz”);      // attachment
$mail->AddAttachment(“/tmp/image.jpg”, “new.jpg”);
$mail->IsHTML(true);                               // send as HTML
$mail->Subject  =  “Here is the subject”;
$mail->Body     =  “This is the <b>HTML body</b>”;
$mail->AltBody  =  “This is the text-only body”;
if(!$mail->Send())
echo “Message has been sent”;
Terlihat bahwa fungsi mail dan phpmailer class memiliki kemiripan. Walaupun ada beberapa tambahan baris/kode yang harus dipakai sehubungan dengan penggunaan SMTP authentication. Penggunaan SMTPauthentication sangat dianjurkan agar skrip tidak dapat diinjeksi untuk mengirim spam, seperti halnya jika menggunakan fungsi mail() built-in PHP.

Tagged:

3 thoughts on “PHP MAILER

  1. muslim 3 Desember 2010 pukul 10:57 am

    ok terimakasih,
    saya akan coba ,,

  2. Agam 15 Februari 2012 pukul 8:39 pm

    jadi, apa bedanya php mailer sama mail yang built in php ?
    apa cuma beda di spam inject saja ?

  3. Dove 21 Juli 2012 pukul 3:08 pm

    Please let me know if you’re looking for a article writer for your site. You have some really great posts and I think I would be a good asset. If you ever want to take some of the load off, I’d love to write some content for your blog in exchange for a link back to mine. Please shoot me an email if interested. Regards!

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: