title: What is the best way to store e-mail accounts data used for sending mailing to customers in PHP?
body: <p>I'm using PEAR::Mail to send a lot of e-mails to our customers. I want to be able to send those e-mails using different SMTP accounts (because of different mailing types). We have like 6-7 accounts, and in the future there might be more. Each of them has different password and we want to be able to store those passwords in database so it's not hardcoded and so you can add them more easily with administrator panel.</p>
  
  <p>I know I want to use encryption for password storing, but imo hashing is not an option here. I want to be able to read those passwords, not only compare the hashes.</p>
  
  <p>I would like to do it with storing encrypted passwords in database but encrypt them with some algorithm. And that's where I have problem - I don't know much about that. I'm attaching my test code for encryption, but I would like your opinion on how should I improve it:</p>
  
  <pre><code>if (!function_exists('hex2bin')) {
  
      function hex2bin($data) {
          $len = strlen($data);
          return pack('H' . $len, $data);
      }
  
  }
  
  $key = $_GET['key'];
  $text = $_GET['text'];
  $encr = $_GET['encr'];
  
  $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
  $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  
  if ($text != null) {
      echo bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv));
  }
  
  if ($encr != null) {
      echo mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, hex2bin($encr), MCRYPT_MODE_ECB);
  }
  </code></pre>