Warning: mail(mail.log): failed to open stream: Permission denied in - email

I am trying to use the function mail in a server over windows with iss7 and i am getting this warning which doesn't let me send mails:
Warning: mail(mail.log): failed to open stream: Permission denied in xxxx
That line is:
mail("mail#myserver.com", "subject", 'body',"From: mail2#myserver.com")
At php.ini i have configured SMTP server, port and sendmail_from like this:
; http://php.net/smtp
SMTP = 128.x.x.xxx
; http://php.net/smtp-port
smtp_port = 110
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = mymail#myserver.com
; 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 = mail.log
I have also created a file called "mail.log" inside C:/php/ and i have changed permissions to write and read for all users.
Also, at phpinfo() safe_mode is Off.
I am currently sending mails with PHPMailer but it is soooo slow that i want to try it with mail function.
Do you know what am I doing wrong?
Thanks.

You should have a mail.log entry in your php.ini file which should log all the mail() function calls. Search for it and if you don't have this line, then it's taking some strange default or previously defined value, so you better define it and point it to the file you have created in your PHP folder and hopefully assigned good permissions to. For more check what phpinfo() is saying about mail.log.
For more info: mail configuration.

Related

STARTTLS error when sending mail through XAMPP

I'm working on a website that has a form which sends an email upon submission using XAMPP. Unfortunately I can't seem to get rid of the error
Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. g20-20020a17090a7d1400b001fd674057d2sm3458984pjl.48 - gsmtp in C:\xampp\htdocs\contact.php on line 25
here are my ini files
php.ini
[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = ***#gmail.com
;sendmail_path =
;mail.force_extra_parameters =
mail.add_x_header=Off
mail.log = "C:\xampp\mailoutput\mail.log"
sendmail.ini
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
;default_domain=mydomain.com
error_logfile=error.log
;debug_logfile=debug.log
auth_username=***#gmail.com
auth_password=***
pop3_server=pop.gmail.com
pop3_username=***#gmail
pop3_password=***
force_sender=***#gmail.com
force_recipient=
hostname=smtp.gmail.com
I've tried changing SMTP to tls://smtp.gmail.com which threw an error that it couldnt connect, then I tried ssl://smtp.gmail.com and changed the port to 465 and I got the same error. Any help would be greatly appreciated, thank you very much!
So I fixed it by changing sendmail_path to
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" which got rid of the warning. Unfortunately though I can't find the email anywhere in my inbox. Any help with this would be appreciated!

LWP Won't Run in CGI Script

I have a CGI script to load publications from BibBase:
#!/usr/bin/perl
use LWP::UserAgent;
my $url = 'https://bibbase.org/show?bib=http://www.example.com/pubs.bib';
my $ua = LWP::UserAgent->new;
my $can_accept = HTTP::Message::decodable;
my $response = $ua->get($url, 'Accept-Encoding' => $can_accept);
print "Content-type: text/html\n\n";
print $response->decoded_content;
(This is copied from BibBase with the exception that the URL is hard-coded.)
I have three webservers running RHEL7 and Apache 2.4 that are configured the same way by Puppet. On all three I can run the script on the command line and get the expected results:
[root#server1 cgi-bin]# ./bibbase_proxy2.cgi | head
Content-type: text/html
<img src="//bibbase.org/img/ajax-loader.gif" id="spinner" style="display: none;" alt="Loading.." />
<div id="bibbase">
<script type="text/javascript">
var bibbase = {
params: {"bib":"http://www.example.com/pubs.bib","host":"bibbase.org"},
When I try to run the script with CGI, I get three different results:
Server1
Unrecognised protocol tcp at /usr/share/perl5/LWP/Protocol/http.pm line 31.
Server2
Can't connect to bibbase.org:443 System error at /usr/share/perl5/LWP/Protocol/http.pm line 51.
Server3
No http output and the error log says AH01215: Out of memory!.
I can't find anything different between the three servers and I can't figure out why the script works fine on the command line and doesn't work when run as a CGI.
I have selinux in permissive mode and it is logging the outgoing request, so I know the script gets that far:
type=AVC msg=audit(1532465859.921:331235): avc: denied { name_connect } for pid=161178 comm="perl" dest=80 scontext=system_u:system_r:httpd_sys_script_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket
For testing, I have set selinux to disabled and restarted the server.
SE-Linux denied the TCP connection.
avc: denied { name_connect }
The default access controls for networking by SELinux are based on the labels assigned to TCP and UDP ports and sockets. For instance, the TCP port 80 is labeled with http_port_t (and class tcp_socket). Access towards this port is then governed through SELinux access controls, such as name_connect and name_bind.
When an application is connecting to a port, the name_connect permission is checked. However, when an application binds to the port, the name_bind permission is checked.
Permissive mode or not, Perl is acting like it was denied a TCP connection. Unrecognised protocol tcp means getprotobyname("tcp") failed inside IO::Socket::IP. That's very, very unusual. One of the ways that can happen is via exactly that SELinux denial.
I'm no SELinux expert, but according to RedHat and Gentoo some SELinux aware applications will ignore the global permissive setting and go it alone. RHEL 7 Apache appears to be one of them. It appears to have its own domain which must be set permissive.
On all three I can run the script on the command line and get the expected results:
There's two reasons for that, and they both have to do with users.
When you run the program you're running as your own user with your own configuration, permissions, and environment variables. In fact, you ran it as root which usually bypasses restrictions. When it runs on the server it runs as a different user, probably the web server user with severe restrictions.
In order to do a realistic test, you need to run it as the same user the web server will. You can use sudo -u for this. For example, if the user is apache...
sudo -u apache ./bibbase_proxy2.cgi
BTW Do not test software as root! Not only is it not going to give you sensible results, but if there's a bug in the software there are no safeguards preventing it from wrecking your system.
The second problem is #!/usr/bin/env perl. That means to run whatever perl is in your PATH. PATH will be different for different users. Running ./bibbase_proxy2.cgi may run with one Perl on the command line and a different one via the web server.
In a server environment, use a hard coded path to Perl like #!/usr/bin/perl.
We tested by rewriting the same script in Python and PHP. Both of them showed error which pointed us in the right direction.
Python urllib2 produced the error
<class 'urllib2.URLError'>: <urlopen error [Errno 16] Device or resource busy>
args = (error(16, 'Device or resource busy'),)
errno = None
filename = None
message = ''
reason = error(16, 'Device or resource busy')
strerror = None
PHP (run as CGI) wouldn't even start:
[Wed Jul 25 15:24:52.988582 2018] [cgi:error] [pid 10369] [client 172.28.6.200:44387] AH01215: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/curl.so' - libssh2.so.1: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
[Wed Jul 25 15:24:52.988980 2018] [cgi:error] [pid 10369] [client 172.28.6.200:44387] AH01215: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/dba.so' - libtokyocabinet.so.9: failed to map segment from shared object: Cannot allocate memory in Unknown on line 0
---- Similar lines for all extensions. ----
It appears that RLimitMEM blocks access to shared memory and that is required for opening sockets. I can't find any documentation, but removing that line makes it work.

smtp server counld not send mail in zend 2

I have am using an SMTP mail server. When I register a new user, I recieve the following error message:
An error occurred
Could not open socket
Additional information:
Zend\Mail\Protocol\Exception\RuntimeException
File:
C:\wamp\www\zendtest\vendor\zendframework\zend-mail\src\Protocol\AbstractProtocol.php:209
Message:
Could not open socket
What should I do?
go to wamp->php->php.ini open this file and find ssl.dll after that remove ; symbol from starting of line. then save the file and restart the wamp. This is working for me.

autoreply program sendmail giving "DSN: Service unavailable" error

I am trying to use an auto reply program for one of the users.
It works fine when I have user email address defined in .forward file but it gives following error when I put it in script:
Jun 28 12:25:38 localhost sendmail[5210]: s5SJPFkN005208: to="|/home/alpha/autoreply.pl", ctladdr=alpha#localhost (501/501), delay=00:00:10, xdelay=00:00:00, mailer=prog, pri=60446, dsn=5.0.0, stat=Service unavailable
Jun 28 12:25:38 localhost sendmail[5210]: s5SJPFkN005208: s5SJPckN005210: DSN: Service unavailable
Do I have have make any changes in sendmail configs (i.e. symbolic link etc)?
Thanks.
1.Have you checked problems mentioned in sendmail FAQ?
Sendmail-FAQ-3.11: Why can't my users forward their mail to a program?
2. On most linuxes sendmail uses procmail as local mailer program.
You may try to execute your script from ~/.procmailrc of the user.
The issue was /etc/smrsh did not have symbolic link for perl which can be defined as
ln -s /usr/bin/perl /etc/smrsh/perl

How do I create a new HTTP::Daemon in perl without root permisson?

Line 271 from HTTP::Proxy is this:
my $daemon = HTTP::Daemon->new(%args) or die "Cannot initialize proxy daemon: $!";
When I try to run this script:
use CGI;
use CGI::Carp(fatalsToBrowser);
use HTTP::Proxy;
my $proxy = HTTP::Proxy->new( port => 8080 ); # Edit: I have tried other ports, too, including 3123, 32789, etc.
$proxy->start;
I get this error message from the browser:
Software error:
Cannot initialize proxy daemon: Operation not permitted at HTTP/Proxy.pm line 271.
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.
I assume this is because I need root permission. Are there any ports I can use that don't require root permission? I don't have the root password to the server.
Edit: Apparently I'm supposed to be able to start it without root with 1025 or greater. How would I set up a stacktrace?
You can use any port (that is not already in use) above 1025. If you are getting that message in your browser (on port 8080?), your daemon is already successfully using that port. I'm not sure what other permission issues it might entail. You could check the documentation or try strace