Friday, February 11, 2011

Mengirim email dengan PHPMailer dan Gmail

Sesuai judul diatas, akan saya coba sedikit tulis bagaimana cara memanggil fungsi phpmailer namun dengan layanan email dari google (Gmail).  Cekidot




Berikut step-stepnya:
  1.  Download source codenya disini 
  2.  Unzip/Extract foldernya ke root atau direktori web anda
  3.  Buat file index.php
  4.  Copas (di copy trus paste ke file index.php) source code dibawah dan ganti text berwarna merah sesuai data anda.
    $mail = new PHPMailer();
     //$mail->IsSMTP(); // telling the class to use SMTP
    // $mail->Host = "localhost"; // SMTP server
    //IsSMTP(); // send via SMTP
    $mail->Host     = "ssl://smtp.gmail.com"; // SMTP server Gmail
    $mail->Mailer   = "smtp";
    $mail->SMTPAuth = true; // turn on SMTP authentication

    $mail->Username = “username@gmail.com”; //
    $mail->Password = “password”; // SMTP password
    $webmaster_email = “username@domain.com”; //Reply to this email ID
    $email=”username@domain.com”; // Recipients email ID
    $name=”name”; // Recipient’s name
    $mail->From = $webmaster_email;
    $mail->FromName = “Webmaster”;
    $mail->AddAddress($email,$name);
    $mail->AddReplyTo($webmaster_email,”Webmaster”);
    $mail->WordWrap = 50; // set word wrap
    $mail->AddAttachment(“/var/tmp/file.tar.gz”); // attachment
    $mail->AddAttachment(“/tmp/image.jpg”, “new.jpg”); // attachment
    $mail->IsHTML(true); // send as HTML
    $mail->Subject = “This is the subject”;
    $mail->Body = “Hi,This is the HTML BODY “; //HTML Body
    $mail->AltBody = “This is the body when user views in plain text format”; //Text Body
    if(!$mail->Send())
    {
    echo “Mailer Error: ” . $mail->ErrorInfo;
    }
    else
    {
    echo “Message has been sent”;
    }
    ?>
     
  5. Buka file class.smtp.php
  6. Paste source code berikut  pada line 104 (#connect to the smtp server)
    $host = “ssl://smtp.gmail.com”;
    $port = 465; 
  7. Save semua perubahan lalu running di browser Anda. Selamat mencoba

5 comments:

  1. Wah, ketemu juga akhirnya. makasih mas, izin muat di blog saya. cek http://aksauncp.blogspot.com/2012/12/mengirim-email-dengan-menggunakan-smtp.html

    ReplyDelete
  2. makasih tutor nya bos, mau coba dulu nich..
    http://ji-software.com

    ReplyDelete
  3. Fatal error: Class 'SMTP' not found in C:\xampp\htdocs\coba\PHPMailer\class.phpmailer.php on line 1209
    gimana solusinya?

    ReplyDelete
  4. Fatal error: Class 'SMTP' not found in C:\xampp\htdocs\platinum\PHPMailer\class.phpmailer.php on line 1443

    solusinya ada yang tau?

    ReplyDelete
  5. forbidden.! klo mau download filenya gan..

    ReplyDelete