*New 11.4 series Release:
2020-07-03: XigmaNAS - released!

*New 12.1 series Release:
2020-04-17: XigmaNAS - 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
Posts: 1
Joined: 20 Mar 2014 18:49
Status: Offline

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


Post by suprkstor »

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

$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

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 !

Posts: 27
Joined: 24 Aug 2015 09:47
Location: Bremen, Germany
Status: Offline

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


Post by UES »

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
Posts: 422
Joined: 25 Aug 2012 09:28
Location: Japan
Status: Offline

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


Post by daoyama »

Thank you for reporting.
Add sendmail_path at r2001. Please wait next build.
NAS4Free (x64-embedded), (arm),
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”