*New 12.1 series Release:
2019-11-08: XigmaNAS 12.1.0.4.7091 - released!

*New 11.3 series Release:
2019-10-19: XigmaNAS 11.3.0.4.7014 - released


We really need "Your" help on XigmaNAS https://translations.launchpad.net/xigmanas translations. Please help today!

Producing and hosting XigmaNAS costs money. Please consider donating for our project so that we can continue to offer you the best.
We need your support! eg: PAYPAL

[HOW TO] Make the php mail() function work

Webserver service.
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
suprkstor
NewUser
NewUser
Posts: 1
Joined: 20 Mar 2014 18:49
Status: Offline

[HOW TO] Make the php mail() function work

#1

Post by suprkstor » 20 Mar 2014 21:54

Hi there !

Nas4free is shipped with msmtp, a sendmail compatible smtp client which can be used with php to send mail from your hosted web applications.

The nas4free way to send mail is unusual; The job is done by php scripts which invoke the msmtp executable instead of using the mail() function(Seen in /etc/inc/email.inc). We can also see the msmtp config file path generated by the webadmin(/var/etc/msmtp.conf).

1)Configure your email settings as usual in System|Advanced|Email

2)According to his manual, without the -C argument msmtp first tries to load /usr/local/etc/msmtprc (This can be verified with msmtp --version). So let's simply create this file and make it readable by www:

Code: Select all

cp /var/etc/msmtp.conf /usr/local/etc/msmtprc
chmod 644 /usr/local/etc/msmtprc
3)Now we have to tell to php where to find msmtp in the php.ini file:

Code: Select all

echo 'sendmail_path = "/usr/local/bin/msmtp -t"' >> /usr/local/etc/php.ini
DONE ! You're now able to send mail from your web apps. To verify this, paste the following lines in an index.php file and load it in your browser.

Code: Select all

<?php
$to      = 'youremail@yourprovider.com';
$subject = 'the subject';
$message = 'hello';

mail($to, $subject, $message);
?>
To make these changes persistent you have to create a shell script in /cf and add it in System|Advanced|Command scripts as a postinit command:

The script:

Code: Select all

#!/bin/bash
cp /var/etc/msmtp.conf /usr/local/etc/msmtprc
chmod 644 /usr/local/etc/msmtprc
echo 'sendmail_path = "/usr/local/bin/msmtp -t"' >> /usr/local/etc/php.ini

To create it:

Code: Select all

mount -uw /cf
mkdir /cf/scripts
nano /cf/scripts/phpmail.sh
chmod 700 /cf/scripts/phpmail.sh
mount -ur /cf
I hope this will help, See you later guys !

UES
Starter
Starter
Posts: 30
Joined: 24 Aug 2015 09:47
Location: Bremen, Germany
Contact:
Status: Offline

Re: [HOW TO] Make the php mail() function work

#2

Post by UES » 24 Aug 2015 18:59

Thank you for this useful hint!
I wonder why this is not done "out of the box"?
Without it, I was not able to send mails from OwnCloud.

User avatar
daoyama
Developer
Developer
Posts: 423
Joined: 25 Aug 2012 09:28
Location: Japan
Status: Offline

Re: [HOW TO] Make the php mail() function work

#3

Post by daoyama » 06 Nov 2015 22:54

Thank you for reporting.
Add sendmail_path at r2001. Please wait next build.
NAS4Free 10.2.0.2.2115 (x64-embedded), 10.2.0.2.2258 (arm), 10.2.0.2.2258(dom0)
GIGABYTE 5YASV-RH, Celeron E3400 (Dual 2.6GHz), ECC 8GB, Intel ET/CT/82566DM (on-board), ZFS mirror (2TBx2)
ASRock E350M1/USB3, 16GB, Realtek 8111E (on-board), ZFS mirror (2TBx2)
MSI MS-9666, Core i7-860(Quad 2.8GHz/HT), 32GB, Mellanox ConnectX-2 EN/Intel 82578DM (on-board), ZFS mirror (3TBx2+L2ARC/ZIL:SSD128GB)
Develop/test environment:
VirtualBox 512MB VM, ESXi 512MB-8GB VM, Raspberry Pi, Pi2, ODROID-C1

Post Reply

Return to “WebServer”