Send Email

From IHRIS Wiki
Revision as of 15:47, 12 August 2015 by Jeddú Villatoro (talk | contribs)

Here is an easy way to send an e-mail using ssmtp

Install ssmtp:

   sudo apt-get install ssmtp

Edit this file: /etc/ssmtp/ssmtp.conf (for security reasons, maybe you should change permissions to this file with chmod, because your password is readable).

   sudo vi /etc/ssmtp/ssmtp.conf

set these lines,:

You need to edit your php.ini:

   sudo vi /etc/php5/apache2/php.ini

Change sendmail_path:

   sendmail_path = /usr/sbin/sendmail -t

Restart apache:

   sudo service apache2 restart

Now you can add these lines to your php file, I added this lines to my page class where I'm printing a resign document.

<source lang="php">

   $message = "You are printing a Resign\r\nMore text...\r\niHRIS e-mail Service";
   // In case any of our lines are larger than 70 characters, we should use wordwrap()
   $message = wordwrap($message, 70, "\r\n");
   $subject = "Printing resign document";
   $to = '';
   if(mail($to,$subject, $message)){
       I2CE::raiseError('Success sending email');
       I2CE::raiseError('Error sending email');


Note: To use a gmail accout for mail() function you had to change the configuration of the gmail account to use less secure applications