pieterjandc Posted January 8, 2017 Share Posted January 8, 2017 Hi, I'm trying to send a mail from a Webpage (PHP), running on a Raspberry Pi (Apache2, PHP5). The Raspberry Pi is behind a Router from my ISP (Telenet) and they block the SMTP-port(25). But I successfully installed sSMTP with all needed configuration, and I'm able to send emails through the mailhub of my ISP (what off course is what they rather like). sudo nano /etc/ssmtp/ssmtp.conf Contains: root=pieterjan@pieterjan.pro mailhub=smtp.telenet.be:587 rewriteDomain=pieterjan.pro hostname=pieterjan.pro UseTLS=YES UseSTARTTLS=Yes AuthUser=my_account@telenet.be AuthPass=my_password AuthMethod=LOGIN FromLineOverride=YES And my Reverse-aliases-file: sudo nano /etc/ssmtp/revaliases Contains: root:my_account@telenet.be:smtp.telenet.be:587 pi:my_account@telenet.be:smtp.telenet.be:587 With this configuration I'm able to send an e-mail using this bash-command: echo "Email body" | mail -s "Test Subject" some-email@address.com Next step: I've tried to change the configuration of PHP5 to use the PHP mail() command: sudo nano /etc/php5/apache2/php.ini Contains: [mail function] ; For Win32 only. ; http://php.net/smtp ;SMTP = localhost ; http://php.net/smtp-port ;smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = pi@pieterjan.pro ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = /usr/sbin/sendmail -t -i -f pi@pieterjan.pro ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(). ;mail.force_extra_parameters = ; Add X-PHP-Originating-Script: that will include uid of the script followed by t$ mail.add_x_header = On ; The path to a log file that will log all mail() calls. Log entries include ; the full path of the script, line number, To address and headers. ;mail.log = ; Log mail to syslog (Event Log on Windows). ;mail.log = syslog I've already tried about everything. I think sendmail should only be used in WAMP and therefore is not applicable. Some say sendmail is automatically linked to ssmtp. But I actually already tried loads of configurations: sendmail_path = /usr/sbin/sendmail -t sendmail_path = /usr/sbin/sendmail -t -i sendmail_path = /usr/sbin/sendmail -t -i -f pi@pieterjan.pro sendmail_path = /usr/sbin/ssmtp -t sendmail_path = /usr/sbin/ssmtp -t -i PHP-code: <?php error_reporting(E_ALL|E_STRICT); ini_set('display_errors',1); $res = mail("pieterjandeclippel@msn.com", "Subject", "Hello!"); echo '<hr>Result was: ' . ( $res === FALSE ? 'FALSE' : 'TRUE') . $res; echo '<hr>'; phpinfo(); ?> This script is hosted here. But nothing actually seems to work, and I'm getting this error: cat /var/log/mail.log Last error from the log-file: Jan 8 20:53:38 pieterjan sSMTP[9209]: Creating SSL connection to host Jan 8 20:53:38 pieterjan sSMTP[9209]: SSL connection using DHE_RSA_AES_128_CBC_SHA1 Jan 8 20:53:38 pieterjan sSMTP[9209]: 550 5.1.0 <www-data@pieterjan.pro> is not an alias of my_account@telenet.be Extra information (entire procedure) : Website What is the problem and how can I fix this? Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted January 8, 2017 Share Posted January 8, 2017 I have mail sending out of my Raspberry Pi using SSMTP, but going through my gmail account. It was super easy: root=$smail Debug=yes mailhub=smtp.gmail.com:587 hostname=irrigation AuthUser=example@gmail.com AuthPass=Pas$weRd123 UseTLS=yes useSTARTTLS=YES RewriteDomain=gmail.com I didn't do anything else, and it just works. So if you can set up a gmail account, your good. Well, I did have to tell google to trust my insecure app, but that's it. Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted January 9, 2017 Solution Share Posted January 9, 2017 Your reverse aliases file does not contain an entry for the www-data user which is what your script is running as. Try adding that and see if it works. Quote Link to comment Share on other sites More sharing options...
pieterjandc Posted January 9, 2017 Author Share Posted January 9, 2017 Haha nice. It works perfectly now. You are a genius. Final configuration sudo nano /etc/ssmtp/revaliases Now contains: root:my_account@telenet.be:smtp.telenet.be:587 pi:my_account@telenet.be:smtp.telenet.be:587 www-data:my_account@telenet.be:smtp.telenet.be:587 Result of mail() is actually '1' now as well. Thanks for the help. I really appreciate. Only 1 question left: Would it be possible to change the configuration so that the mail doesn't appear to be coming from www-data@pieterjan.pro ? Quote Link to comment Share on other sites More sharing options...
kicken Posted January 9, 2017 Share Posted January 9, 2017 Use the fourth parameter to the mail() function to define custom headers and set the From address. See the examples in the manual. In general I always recommend using a library for mail such as Swiftmailer. Using mail() directly is cumbersome and error prone. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.