Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Tuesday, October 2, 2012

PHP = Send Email + Attach file

SEMALAM :

Pegi opis KJ (Kelana Jaya ok) present company website to CEO... almaklum le orang penting huhu (sebenarnye x pun.. cume ganti bos.. sebab bos ade hal lagi penting dari setakat nak present website ni...)

Dan2 lepas present... CEO request pada bahagian senarai keje kosong tu.. nak buat canggih sikit... supaya sape2 yang tgk iklan kat website boleh terus upload resume dari website to jugak.. and terus terbang resume tu ke email HR...

Hu hu hu.......

Pening jap... toing toing toing....


Otak dok pikir.............

Macam kena ..... Buat database + relate dengan form + pastu ?????? macam mane nak attach kat email lak???

Eeee macam susah je.... tapi mulut ni gatal cakap kat CEO "BOLEH BOS!!!".... kepala lak ringan je ANGGUK ANGGUK.... (Macam terrorrrrr lah sangatttt aku ni!!!)

Balik umah dah termenung....... Dok kat toilet pun termenung.....

HARI NI:

Masuk opis temenung depan mr.lappy and otak jalan mcm enjin kete camry.... (camry lah sangat!!! haha..)

TRY & ERROR is the best experience (love this way... masuk otak melekat tak keluar2..)

Ok... macam mane nak buat uploas file resume kat website and bila send terus masuk attachment tu kat email orang?...

Begini cara nye... ting ting ting.....

1st STEP:
You guys kena copy paste coding kat bawah ni.. and save kan file ni dengan nama career.php

 <html>   
  <head>   
  <title>PHP ERNI MAT</title>   
  </head>   
  <body>   
  <form action="php_sendmail_upload.php" method="post" name="form1" enctype="multipart/form-data">    
   <table width="100%">    
   <tr>   
   <td colspan="2" bgcolor="#EEEEEE" class="style7"><div align="center">   
    <p><br />   
    Minat nak keje? Jom upload resume korang kat borang ni ;D <span class="style27"><span class="style27"><br />    
    <br />   
    </span></span></p>   
    </div></td>   
   </tr>   
   <tr>   
   <td bgcolor="#EEEEEE"><div align="center"><span class="style27">Your Full Name </span></div></td>   
   <td bgcolor="#EEEEEE"><input name="txtFormName" type="text" size="50" /></td>   
   </tr>   
   <tr>    
   <td width="26%" bgcolor="#EEEEEE"><div align="center"><span class="style27">Desired Job Tittle </span></div></td>    
   <td width="74%" bgcolor="#EEEEEE"><input name="txtDescription" type="text" id="txtDescription" size="50" />  </td>   
   </tr><tr>    
   <td bgcolor="#EEEEEE"><div align="center"><span class="style27">Your Email</span></div></td>    
   <td bgcolor="#EEEEEE"><input name="txtFormEmail" type="text" size="50" /></td>    
   </tr>    
   <tr>    
   <td bgcolor="#EEEEEE"><div align="center"><span class="style27">Attach Resume </span></div></td>    
   <td bgcolor="#EEEEEE"><input name="fileAttach" type="file"></td>    
   </tr>    
   <tr>    
   <td bgcolor="#EEEEEE">&nbsp;</td>    
   <td bgcolor="#EEEEEE"><input type="submit" name="Submit" value=":: SEND TO US ::" /></td>    
   </tr>    
   </table>    
   </form>    
  </body>   
  </html>   

2nd STEP:

Bukak file baru... pastu copy paste coding kat bawah ni.. lepas tu save nama file tu sebagai php_sendmail_upload.php

   <html>   
   <head>   
   <title>PHP ERNI MAT</title>   
   </head>   
   <body>   
   <?   
   $strTo = 'tukarEmailPenerima@emailApeje.com';   
   $strSubject = 'Resume '.$_POST["txtFormName"];   
   $strMessage = nl2br($_POST["txtDescription"]);   
   //*** Uniqid Session ***//   
   $strSid = md5(uniqid(time()));   
   $strHeader = "";   
   $strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"]."";   
   $strHeader .= "MIME-Version: 1.0\n";   
   $strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";   
   $strHeader .= "This is a multi-part message in MIME format.\n";   
   $strHeader .= "--".$strSid."\n";   
   $strHeader .= "Content-type: text/html; charset=utf-8\n";   
   $strHeader .= "Content-Transfer-Encoding: 7bit\n\n";   
   $strHeader .= $strMessage."\n\n";   
   //*** Attachment ***//   
   if($_FILES["fileAttach"]["name"] != "")   
   {   
   $strFilesName = $_FILES["fileAttach"]["name"];   
   $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));   
   $strHeader .= "--".$strSid."\n";   
   $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";   
   $strHeader .= "Content-Transfer-Encoding: base64\n";   
   $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";   
   $strHeader .= $strContent."\n\n";   
   }   
   $flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error //   
   if($flgSend)   
   {   
   echo "Mail send completed.";   
   }   
   else   
   {   
   echo "Cannot send mail.";   
   }   
   ?>   
   </body>   
   </html>   

Pastu letak kedua dua file ni dalam folder yang same.... and run kan si file bernama career.php tadi... you guys akan dapat satu borang berbentuk macam kat bawah ni....

Tadaaaaaaaa.....!!!!

PHP ERNI MAT

Minat nak keje? Jom upload resume korang kat borang ni ;D

Your Full Name
Desired Job Tittle
Your Email
Attach Resume

Akhirnye berjaya jugak merialisasikan impian CEO nak ade borang upload ni kat website...

Senang je rupenye wat borang online gune PHP.. pastu automaik attach file yang kita upload tu ke email penerima...

Paling terkesima sekejap... TAKYAH SUSAH2 PAKAI DATABASE!!!... hohoho...

Walaupun sesetengah programmer cakap benda ni senang je...

Tapi tak semua programmer tau ye tak???

So sharing is caring!!

Hope u guys try kalau ade bos2 korang mintak benda2 macam ni dalam website.... 

Tataaaa..!!!!! 

Read more…

Wednesday, February 8, 2012

Compare date with PHP

Selalu nye kan... kalau nak wat coding PHP untuk compare tarikh mesti pening... kena wat if else utk day, month, year.... Sampai pening2... bile search on pakcik google... at last i found this simple of code yg wat my life happy sgt2... ;D

// your first date coming from a mysql database (date fields)
$dateA = '2008-03-01 13:34';

// your second date coming from a mysql database (date fields)
$dateB
= '2007-04-14 15:23';

if
(strtotime($dateA) > strtotime($dateB)){
// bla bla

}

nak tau lebih details tentang comparison tarikh ni... try browse from this source
http://www.thetricky.net/php/Compare%20dates%20with%20PHP

Wish you enjoy it... ;D

Read more…

Tuesday, December 13, 2011

Cakephp system tak run bile masuk dalam xampp

Hi kengkawan... penah tak alami problem dgn cakephp system yang tak run bila masukkan dalam xampp?... dah 2 ari dah kena problem ni... bile kat server jalan ok je.. tapi bile nak setkan kat xampp laptop problem lak.. ingatkan salah kat coding ke... tak betulkan database ke.. cek punye cek.. godek punye godek sampai penat... last2 tanye kat pakcik google je.... pakcik google ni pandai tauu... dia cakap try buat macam ni......................................


  1. Open “httpd.conf” located on “apacheconf” folder.
  2. Then uncomment the line that contains “mod_rewrite”.
  3. Pastu jangan lupa restart xampp... Stop kan apache dgn mysql.. pastu Start semula...
  4. This is needed to enable Cake’s pretty URL such as
  5. http://localhost/cake/users/view” instead of “http://localhost/cake/index.php/users/view”.

Try punye try.... tak jadi gak... nak tau tak nape tak jadi..........
Psssstttt... sebab terlupe nak ikut step pakcik google yg no.3... hihihihi....
Jangan give up... try sekali lagi.....
Pastu... yeahhh..... menjadiiiii.....
Skrg baru boleh update cakephp system yang burukkkkkkkkkkk ni kat laptop... disebabkan bukan saya yang buat system ni.. so boleh lah kutuk burukkk kan.. hahaha.... =p

Read more…

Tuesday, April 26, 2011

PHP validation for radio button


Baru tau rupe2nye.. validation utk textfield tak same dgn validation utk radio button.. patut lah puas buat memula tak jadi2... huhu... =D


function survey()
{
//validation untuk textfield
if (document.form1.position.value == "")
{
alert("Please insert your position");
document.form1.position.focus();
return false;
}

//validation utk radio button (lebih dari 1 radio button yg sama nama)
if (( document.form1.speed[0].checked == false )&&
( document.form1.speed[1].checked == false )&&
( document.form1.speed[2].checked == false )&&
( document.form1.speed[3].checked == false )&&
( document.form1.speed[4].checked == false ))
{
alert("Please tick your question number 1");
return false;
}
}

Read more…