Jawaad's Archive

Cara konfigurasi phpmailer menggunakan Gmail Account

This item was filled under [ Code Snippet, PHP ]

Berikut settingan phpmailer menggunakan jasa account gmail.

<?php
IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "ssl"; // SSL Support
$mail->Host = "smtp.gmail.com"; // SMTP servers
$mail->Port = 465; // Port
$mail->Username = "usernamenya@gmail.com"; // SMTP username (pakai @gmail.com)
$mail->Password = "passwordnya"; // SMTP password
?>

Ubah bagian username dan password sesuai dengan account Gmail Anda.
semoga bermanfaat

NB: bagi yg blm pernah menggunakan script mail phpmailer, saya sarankan untuk membaca artikel berikut:
http://www.nusansifor.com/2008/11/cara-menggunakan-phpmailer-dengan-smtp-berikut-attachment

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 5.00 out of 5)
Loading ... Loading ...
Popularity: 5,393 views
Tagged with: [ , ]

JWD-029: TrueFireConsultants (TFC) – Jakarta – December 2008

This item was filled under [ Portfolio, Web CMS ]

Product ID: JWD-029
Name: TrueFireConsultants (TFC)
Status: Progress Done
Launch: December 2008

Description: Web Company Profile.
Address: http://www.truefireconsultants.com (offline)

System:
- Using PHP & MySQL (Linux) Online

Modules:
- URL friendly for SEO (use a rewrite url)
- CMS Administrator (Content Management System)
- Organize additional Information
-
Organize Contact Information
- Organize Statis page with
editor online WYSIWYG
- Contact us form automatic sending to email (manage by admin)
- Block Header
- Block Currency (Exchange Rates)
- Block RSS News Feed
- Block Latest Project

Coorporate with IMS (Internet Media Solution http://internetmedia-solutions.com)

Designed by Mukie Dardjati Muza.

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Loading ... Loading ...
Popularity: 1,427 views
Tagged with: [ , ]

Script PHP Mengambil Nilai Tukar Valuta Asing BCA

This item was filled under [ Code Snippet, PHP ]

Berikut adalah script php untuk menampilkan kondisi mata uang valuta asing mengambil data yang bersumber dari http://www.klikBCA.com.

Dengan dua metode, menggunakan curl atau juga bisa menggunakan file_get_content().

Pertama-tama kita buat file fungsi_kurs_bca.php, yg isinya sbb.:

<?php
/*
Ambil Nilai Valuta Kurs Dari BCA Versi 1.0
Tanggal: 2008-11-19 22:17
Original dari azza (broadband.or.id/forum/)
dimodif oleh: jinbatsu (http://www.nusansifor.com) 
yg dimodif:
	- menggunakan CURL sebagai alternatif dari file_get_contents (hususnya buat yg gak bisa di hostingan2 tertentu)
	- penempatan output  titik koma dan tanda petik yg mengakibatkan fatal error dibeberapa hostingan
	- menambah number format, supaya terlihat ada titik pada ribuan nya
*/
error_reporting (E_ALL);
//
// Ubah menjadi 3600 untuk cache 1 jam, ketika semuanya sudah berjalan normal.
// Menggunakan cache berarti tidak perlu membuka koneksi ke klikbca
// setiap kali halaman dibuka << ini PENTING! menghemat waktu, dan mengurangi proses server.
//
$nkurs['cachetime'] = 3600; /* ubah jadi 3600 atau lebih */
//
// Hilangkan mata uang yang tidak mau ditampilkan.
//
$nkurs['curr'] = array ('USD', 'SGD', 'HKD', 'CHF', 'GBP', 'AUD', 'JPY', 'SEK', 'DKK', 'CAD', 'EUR', 'SAR');
//
// Dari sini kebawah, ubah kalau mengerti aja.
// Atau tanya dulu di: broadband.or.id/forum/viewforum.php?f=7 (database forumnya sekarang udah gak ada, silahkan dicek  lagi)
//
// menggunakan CURL, jika file_get_contents tidak bisa dihostingan Anda, baca manual PHP untuk selengkapnya
function curl_get_file_contents($URL) {
	$c = curl_init();
	curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($c, CURLOPT_URL, $URL);
	$contents = curl_exec($c);
	curl_close($c);
	if ($contents) return $contents;
	else return FALSE;
}
$nkurs['scriptpath'] = dirname (__FILE__);
$nkurs['cachefile'] = $nkurs['scriptpath'] . '/cache.txt';
if (!file_exists ($nkurs['cachefile']) || !is_writable ($nkurs['cachefile'])){ die ('File cache.txt belum ada atau belum writable.<br />Buat file:
 
<div>::CODECOLORER_BLOCK_1::</div>
 
<br />Lalu CHMOD ke 666'); }
if (filemtime ($nkurs['cachefile']) <= ( time () - $nkurs['cachetime'] ) && $handle = curl_get_file_contents("http://www.klikbca.com/individual/silver/ind/rates.html"))  {
	$handle = explode ('<table border="0" cellspacing="0" cellpadding="0" class="testL">', $handle);
	$handle = explode ('</table>', $handle[1]);
	$handle = explode ('<TR', $handle[0]);
	$nkurs['data'] = array ();
	foreach ($handle as $val) {
		if (!isset ($nkurs['remotelastupdate'])) {
			$nkurs['remotelastupdate'] = explode ('<font color="black" size="1" face="Arial">', $val);
			$nkurs['remotelastupdate'] = explode ('</font>', $nkurs['remotelastupdate'][1]);
			$nkurs['remotelastupdate'] = explode ('/', $nkurs['remotelastupdate'][0]);
			$nkurs['remotelastupdate'] = trim ($nkurs['remotelastupdate'][0]) . ' / ' . trim ($nkurs['remotelastupdate'][1]);
		} else {
			$val = explode ('<center>', $val);
			$val = explode ('</center>', $val[1]);
			$curr = trim (str_replace ('&nbsp;', '', $val[0]));
			$val = explode ('&nbsp;', $val[1]);
			$sell = explode ('align="right">', $val[0]);
			$sell = trim ($sell[1]);
			$buy = explode ('align="right">', $val[1]);
			$buy = trim ($buy[1]);
			$nkurs['data'][$curr] = array ($sell, $buy);
		}
	}
	$tocache = array ();
	foreach ($nkurs['data'] as $key => $val) {
		$tocache[] = $key . '|' . $val[0] . '|' . $val[1];
	}
	$tocache[] = 'remotelastupdate|' . $nkurs['remotelastupdate'];
	$tocache = implode ("\n", $tocache);
	$handle = fopen ($nkurs['cachefile'], 'w');
	fwrite ($handle, $tocache);
	fclose ($handle);
} else {
	$handle = file ($nkurs['cachefile']);
	$nkurs['data'] = array ();
	foreach ($handle as $val) {
		$val = explode ('|', $val);
		if ($val[0] != 'remotelastupdate') {
			$nkurs['data'][$val[0]] = array ($val[1], trim ($val[2]));
		}
		else
		{
			$nkurs['remotelastupdate'] = $val[1];
		}
	}
}
//
// Output
//
$output = "\n";
$margin = '';
$output .= $margin . '<div id="nKurs">' . "\n";
$output .= $margin . '	<table width="100%" border="0" cellspacing="1" cellpadding="0">' . "\n";
$output .= $margin . '		<tr><th>Mata Uang</th><th>Jual</th><th>Beli</th></tr>' . "\n";
$rowclass = 'row1';
foreach ($nkurs['data'] as $key => $val) {
	if (in_array ($key, $nkurs['curr'])) {
		if ($rowclass == 'row1'){ $rowclass = 'row2'; }else{ $rowclass = 'row1'; }
		$output .= $margin . '		<tr><td align="center" class="curr ' .$rowclass . '">' . $key . '</td><td align="right" class="' . $rowclass . '">' . number_format($val[0], 2) . '</td><td align="right" class="' . $rowclass . '">' . number_format($val[1], 2) . '</td></tr>' . "\n";
	}
}
$output .= $margin . '	</table>' . "\n";
$output .= $margin . '	<cite><a href="http://www.klikbca.com/" rel="external" title="Source: KlikBCA">' . $nkurs["remotelastupdate"] . '</a></cite>' . "\n";
$output .= $margin . '</div>' . "\n";
echo $output;
?>

Lalu kita siapkan file berikutnya kurs_bca.php, yaitu sbb.:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nilai Tukar Mata Uang Asing dari KlikBCA</title>
<link href="kurs_bca.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
<?php
include_once("fungsi_kurs_bca.php");
?>
 
</body>
</html>

Dan untuk men-design tampilan lebar dan warna, kita buat file kurs_bca.css, yg isinya sbb.:

#nKurs {
	width: 170px;
	background: #FFFFFF;
	padding: 1px;
}
#nKurs table {
	border: 1px solid #333399;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
#nKurs table th {
	color: #FFFFFF;
	background-color: #333399;
	font-size: 10px;
	padding: 2px 0px;
}
#nKurs table td {
	font-size: 10px;
	color: #333399;
	padding: 1px 2px;
}
#nKurs table td.curr {
	font-weight: bold;
}
#nKurs table td.row1 {
	background-color: #EEF1F6;
}
#nKurs table td.row2 {
	background-color: #EBF2FF;
}
#nKurs cite {
	display: block;
	color: #333399;
	font-style: normal;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
	text-align: center;
}
#nKurs a:link, #nKurs a:visited {
	color: #333399;
	text-decoration: none;
}
#nKurs a:hover {
	color: #FF0000;
}

Demo: klik disini
Download file contoh script komplit nya:

  kurs_bcaV2.rar (2.6 KiB, 3,446 hits)

semoga bermanfaat :mrgreen:
oya tambahan, untuk menggunakan metode fungsi file_get_contents(), ubah code

curl_get_file_contents("alamat url nya")

menjadi:

file_get_contents("alamat url nya", "r")

thx to balaiweb atas suggest nya.
jika ada masukan lain, silahkan share…

UPDATE:
link url klik bca exchange rate berubah (file download sudah termasuk perubahan alamat url nya)

PERHATIAN!!
untuk mencoba script berjalan dgn baik, silahkan diubah variabel berikut:

$nkurs['cachetime'] = 3600;

menjadi:

$nkurs['cachetime'] = 0;

Setelah OK, ubah kembali menjadi 3600 atau lebih, untuk hemat resource.

1 Star2 Stars3 Stars4 Stars5 Stars (8 votes, average: 5.00 out of 5)
Loading ... Loading ...
Popularity: 12,409 views
Tagged with: [ , , , , , , ]

Menyisipkan Array

This item was filled under [ Code Snippet, PHP ]

Cara menyisipkan element baru kedalam array pada script PHP, adalah sbb.:

<?php
$array_kota = array("cirebon", "tegal", "pekalongan"); // data array awal
array_push($array_kota, "jakarta", "surabaya"); // disisipkan array baru
// hasilnya adalah sbb:
echo $array_kota[0] . "<br />"; // cirebon
echo $array_kota[1] . "<br />"; // tegal
echo $array_kota[2] . "<br />"; // pekalongan
echo $array_kota[3] . "<br />"; // jakarta
echo $array_kota[4] . "<br />"; // surabaya
?>
1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 4.33 out of 5)
Loading ... Loading ...
Popularity: 1,784 views
Tagged with: [ , ]

Free Simple ToDoList Resources

This item was filled under [ Free Software ]

Aplikasi ToDoList yg mudah dan lumayan komplit dan fleksibel hampir semua kubutuhan bisa terhandle.
Basic Feature nya adalah:

  • Simple interface
  • Support for hierarchical data
  • Numbered items/subitems
  • Open file format
  • Freeware

Tambahan Feature2 lain:

  • Dapat dikunci/encrypt file nya
  • Comment berupa Plain Text ataupun Rich Text Editor
  • Dan banyak lainnya

Download:

1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 5.00 out of 5)
Loading ... Loading ...
Popularity: 1,754 views
Tagged with: [ , , , , ]

Cara menggunakan phpmailer dengan SMTP berikut attachment

This item was filled under [ Code Snippet, Javascript, PHP ]

mengirim email menggunakan phpmailer dengan mudah.
berikut struktur folder dan file yg akan kita persiapkan:

www/mail_setup/class.phpmailer.php
www/mail_setup/class.smtp.php
www/mail_setup/mail.php
www/kontak.php

file mail.php isinya adalah setup configurasi SMTP:

<?php
// konfigurasi
$set_smtp_host = "mail.namadomain.com";
$set_smtp_user = "user_email@namadomain.com";
$set_smtp_pass = "password-nya";
 
require_once ('/mail_setup/class.smtp.php');
require_once ('/mail_setup/class.phpmailer.php');
 
$PHPMAILER_LANG = array();
 
$PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
                                     'recipient email address.';
$PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
$PHPMAILER_LANG["execute"] = 'Could not execute: ';
$PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
$PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
$PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
$PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
                                       'recipients failed: ';
$PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
$PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
$PHPMAILER_LANG["file_access"] = 'Could not access file: ';
$PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: ';
$PHPMAILER_LANG["encoding"] = 'Unknown encoding: ';
 
$mail = new PHPMailer();
 
// setting SMTP
$mail->IsSMTP();  // send via SMTP
$mail->Host     = $set_smtp_host; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = $set_smtp_user;  // SMTP username
$mail->Password = $set_smtp_pass; // SMTP password
?>

dan ini contoh file kontak.php

<?php
// MAIL & ATTACHMENT
$isi = "";
$error = 0;
$form = 1;
$max_file = 1048577; // 1 MB
 
if($_POST['submit']) {
	$name = strip_tags($_POST[name]);
	$email = strip_tags($_POST[email]);
	$subject = strip_tags($_POST[subject]);
	$file1_path = $_FILES['file_att']['tmp_name'];
	$file1_name = $_FILES['file_att']['name'];
	$file1_type = $_FILES['file_att']['type'];
	$file1_size = $_FILES['file_att']['size'];
	// cek file
	if($file1_size > 0) {
		if($file1_size <= $max_file) {
			require_once ('mail_setup/mail.php');
			$mail->From     = $email; // email pengirim
			$mail->FromName = $name; // nama pengirim
			$mail->AddAddress($set_email_hrd, $set_web_title); // penerima
			$mail->AddReplyTo($email, $name); // kirim balik reply ke
			$mail->WordWrap = 50; // set word wrap
			$mail->AddAttachment($file1_path, $file1_name);
			$mail->IsHTML(false);                               // send as HTML
			$mail->Subject   =  $subject;
			$mail->Body     .=  "Name: $name\n";
			$mail->Body     .=  "Email: $email\n";
			$mail->Body     .=  "\n\n";
			$mail->Body     .=  "----------\n";
			$mail->Body     .=  $set_web_title."\n";
			$mail->Body     .=  $web."\n";
			if(!$mail->Send()) {
				$error = 1;
				echo "<script>alert('Sorry, Mail Sent Error..., please try again.');</script>";
			} else {
				// EMAIL sukses terkirim
				$email_success = "<div class=\"good\">Email Sent Sucessfull.<br/>Thank You.</div>";
				$form = 0;
			}
		} else {
			$error = 1;
			echo "<script>alert('File terlalu besar! (Max. ".format_size($max_file).")');</script>";
			$error_cv = "<br/><span class=\"warning\">File terlalu besar, (Max. ".format_size($max_file).")</span>";
		}
	} else {
		$error = 1;
		$error_cv = "<br/><span class=\"warning\">File Kosong!</span>";
		echo "<script>alert('File Kosong!');</script>";
	}
}
if($error == 1) {
	$error_view = "<span class=\"warning\">Error!</span>";
}
if($form == 1) {
	// FORM APPLY
	$isi .= "<hr noshade=\"noshade\" size=\"1\" color=\"#cccccc\" width=\"80%\"><br/>";
	$isi .= "<div align=\"center\">";
	$isi .= "<form method=\"POST\" name=\"myform\" enctype=\"multipart/form-data\" style=\"padding:0; margin:0; \">";
	$isi .= "	<table border=0 cellspacing=0 bgcolor=\"#ffffff\" cellpadding=0 width=\"98%\">";
	$isi .= "		<tr>";
	$isi .= "			<td bgcolor=\"#ffffff\">";
	$isi .= "				".$error_view;
	$isi .= "				<table border=0 cellspacing=1 cellpadding=2 bgcolor=\"#ffffff\" width=\"100%\">";
	$isi .= "					<tr>";
	$isi .= "						<td colspan=2>";
	$isi .= "							<h2>Form </h2>";
	$isi .= "						</td>";
	$isi .= "					</tr>";
	$isi .= "					<tr>";
	$isi .= "						<td bgcolor=\"#ffffff\" width=100>";
	$isi .= "							Name";
	$isi .= "						</td>";
	$isi .= "						<td bgcolor=\"#ffffff\">";
	$isi .= "							: <input type=\"text\" name=\"name\" size=\"30\" value=\"".$name."\">";
	$isi .= "						</td>";
	$isi .= "					</tr>";
	$isi .= "					<tr>";
	$isi .= "						<td bgcolor=\"#ffffff\" width=100>";
	$isi .= "							Email";
	$isi .= "						</td>";
	$isi .= "						<td bgcolor=\"#ffffff\">";
	$isi .= "							: <input type=\"text\" name=\"email\" size=\"30\" value=\"".$email."\">";
	$isi .= "						</td>";
	$isi .= "					</tr>";
	$isi .= "					<tr>";
	$isi .= "						<td bgcolor=\"#ffffff\" width=100 valign=top>";
	$isi .= "							File";
	$isi .= "						</td>";
	$isi .= "						<td bgcolor=\"#ffffff\">";
	$isi .= "							: <input type=\"file\" name=\"file_att\" size=\"30\">";
	$isi .= "							(Max. ".format_size($max_file).")".$error_cv;
	$isi .= "						</td>";
	$isi .= "					</tr>";
	$isi .= "						<td bgcolor=\"#ffffff\" colspan=2>";
	$isi .= "							<input type=\"submit\" name=\"submit\" value=\"Submit\">";
	$isi .= "						</td>";
	$isi .= "					</tr>";
	$isi .= "				</table>";
	$isi .= "			</td>";
	$isi .= "		</tr>";
	$isi .= "	</table>";
	$isi .= "</form>";
	$isi .= "</div>";
}	
echo $isi;
?>

Download file:

  contoh_email_smtp_phpmailer.zip (20.3 KiB, 3,232 hits)

(sudah termasuk class phpmailer dan contoh file)

Tambahan fungsi format_size sbb.:

function format_size($rawSize) { 
   if ($rawSize / 1048576 > 1)  return round($rawSize/1048576, 1) . 'MB'; 
   elseif ($rawSize / 1024 > 1) return round($rawSize/1024, 1) . 'KB'; 
   else  return round($rawSize, 1) . 'bytes'; 
}

Note: fungsi format_size tdk termasuk pada download script zip.

1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 4.80 out of 5)
Loading ... Loading ...
Popularity: 9,674 views
Tagged with: [ , , ]

Halaman ini di eksekusi dalam waktu 3.538 detik! (sedeng lah segini mah...)