Send Email: Difference between revisions
From IHRIS Wiki
No edit summary |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Here is an easy way to send an e-mail using [https://wiki.debian.org/sSMTP ssmtp] | Here is an easy way to send an e-mail using [https://wiki.debian.org/sSMTP ssmtp] This process was tested on Ubuntu 12.04 with iHRIS Manage 4.1.9. | ||
Install ssmtp | Install ssmtp | ||
sudo apt-get install ssmtp | sudo apt-get install ssmtp | ||
Line 28: | Line 28: | ||
sudo service apache2 restart | sudo service apache2 restart | ||
Now you can add these lines to your php | Now you can add these lines to your php page class, i.e. into the save() function. | ||
<source lang="php"> | <source lang="php"> | ||
$message = "You are | $message = "You are saving a record\r\nMore text...\r\niHRIS e-mail Service"; | ||
// In case any of our lines are larger than 70 characters, we should use wordwrap() | // In case any of our lines are larger than 70 characters, we should use wordwrap() | ||
$message = wordwrap($message, 70, "\r\n"); | $message = wordwrap($message, 70, "\r\n"); | ||
$subject = " | $subject = "e-mail notification"; | ||
$to = 'YOUR_ACCOUNT@gmail.com'; | $to = 'YOUR_ACCOUNT@gmail.com'; | ||
Line 46: | Line 45: | ||
</source> | </source> | ||
''Note:'' To use a gmail accout for mail() function you had to change the configuration of the gmail account to use [https://www.google.com/settings/security/lesssecureapps less secure applications] | '''Note:''' To use a gmail accout for mail() function you had to change the configuration of the gmail account to use [https://www.google.com/settings/security/lesssecureapps less secure applications] |
Latest revision as of 16:19, 12 August 2015
Here is an easy way to send an e-mail using ssmtp This process was tested on Ubuntu 12.04 with iHRIS Manage 4.1.9.
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,:
mailhub=smtp.gmail.com:587 UseSTARTTLS=YES AuthUser=<YOUR-EMAIL>@gmail.com AuthPass=<YOUR-PASSWORD>
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 page class, i.e. into the save() function.
<source lang="php">
$message = "You are saving a record\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 = "e-mail notification"; $to = 'YOUR_ACCOUNT@gmail.com';
if(mail($to,$subject, $message)){ I2CE::raiseError('Success sending email'); }else{ I2CE::raiseError('Error sending email'); }
</source>
Note: To use a gmail accout for mail() function you had to change the configuration of the gmail account to use less secure applications