Thursday, February 19, 2015

How To Fix Multiple Attachments Problem in PHPMailer?

Before sending email with multiple attachments, you need to fix some bugs in the PHPMailer library. You can download the PHPMailer library from

To be able to send multiple attachments in email via PHPMailer, following patch has to be applied to 'class.phpmailer.php' (methods "AddAttachment" and "AddStringAttachment"))
$this->attachment[] = array(
0 => $path,
1 => $filename,
2 => $name,
3 => $encoding,
4 => $type,
5 => false, // isStringAttachment
6 => 'attachment',
7 => 0

$this->attachment[] = array(
0 => $path,
1 => $filename,
2 => $name,
3 => $encoding,
4 => $type,
5 => false, // isStringAttachment
6 => 'attachment',
7 => uniqid()

The problem is caused by the cid-uniqueness check in AttachAll(), in combination with attachment[7] being set to 0 in AddAttachment and AddStringAttachment.

Now after patching the library, to send multiple attachments is very easy in PHPMailer. You need to simply add a following piece of codes and you are ready to send email with multiple attachments.
$mail->addAttachment('/tmp/image1.jpg', '1.jpg');    // Attachment 1
$mail->addAttachment('/tmp/image2.jpg', '2.jpg');    // Attachment 2


Monday, February 9, 2015

How to Install & Enable Curl on Ubuntu LAMP Stack?

You only have to install the php5-curl library.
Alternative 1
You can do this by running
sudo apt-get install php5-curl
You will need to restart the server afterwards:
sudo service apache2 restart

Alternative 2
sudo apt-get update
sudo apt-get install php5

sudo apt-get install libapache2-mod-php5

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
and then:
cd /etc/php5/apache2/

sudo nano php.ini
and add this command:
the last thing restart apache.


Thursday, February 5, 2015

How To Solve Disallowed Key Characters Error In Codeigniter?

I was trying to implement jQuery AJAX form data serialize using Codeigniter and getting error "Disallowed Key Characters". This error bugged me for hours.

I opened the system/codeigniter/system/core/input.php file:
Find the function _clean_input_keys($str)


exit('Disallowed Key Characters.');


  exit('Disallowed Key Characters.'. $str);

It will tell you what characters are causing this error or problem. The problem was naming of the input field. I named input field as

<input type="text" name="myarray['data1']" \>

And I just changed the input's name.

<input type="text" name="myarray[data1]" \>

And it worked. :)