Category Archives: PHP

Configure Postfix/Sendmail for PHP mail() in Ubuntu

Actually configure Postfix or Sendmail for PHP mail() is the same. Both of them run the /usr/sbin/sendmail binary. It is quite confusing if we just look at the name of the binary but this is what Postfix did.

For more information, take a look at the Postfix Manual – sendmail.

For the PHP setting, open the /etc/php5/apache2/php.ini and configure the sendmail_path. Continue reading Configure Postfix/Sendmail for PHP mail() in Ubuntu

PHP – Convert Special Characters to HTML Entities

I was working on a legacy CMS which has a HTML form with ISO-8859-1 encoding. I found that whenever i got an Apostrophe (‘) in the string, the data cannot be persisted.

I guess it should be some encoding problem which makes the database fail to persist the data. So i try to use the PHP str_replace function to replace those Apostrophe but it has never replaced them successfully.

Finally, i got the solution. PHP provide a function called htmlspecialchars which will substitute the following special characters into HTML entities. Continue reading PHP – Convert Special Characters to HTML Entities

PHP – Send Attachment with PHP mail()

Update @ 2014-03-10: If the following piece of code doesn’t work, you could try the comment written by karmaprod.

Update @ 2014-01-17: You may need to change the PHP_EOL setting in Windows environment as suggested by Rene.

Update @ 2015-02-13: Replace all “/r/n” to PHP_EOL as suggested by Rene and Tomas for windows environment and sending image attachment.

By default, the PHP mail() does not support sending email with attachment. In order to send an attachment, u can either use the PEAR package or PHPMailer. But in reality, the hosting server may not provide these kinds of third party libraries.
Continue reading PHP – Send Attachment with PHP mail()