I got a strange behavior. I am using xampp installed on Win7 and PHPMailer class.
When I run a simple .php script to send a mail from the browser, all goes well but if I run the same script using command prompt with php sufix (c:..... php c:\xampp\htdocs......script.php) i got the following error message
"Helo command rejected: need fully-qualified hostname"
Any ideea why?
I can see in ECHLO that when run from browser i got the right server address (my hostname) but when i access the script from command promt i got as a host name the machine name. Can this be changed or set-up to run like from the browser? I guess this is the issue, the hostname.
Thank you
As the others have mentioned, when you're not in an HTTP environment, and if your host name is not set correctly, or is unavailable to PHP for some reason, there may be difficulty obtaining the host name that's used in HELO/EHLO commands. You can provide one explicitly by setting the Hostname property:
$mail->Hostname = 'myserver.example.com';
Note that this is different to the Host and Helo properties; see the docs for the differences.
Most likely the script relies on some environment variable to use as its own hostname, probably $_SERVER['HTTP_HOST']. This will be set when running from your webserver, but not over command line because it's not an HTTP environment.
If you enable full error reporting you may see something like this in the error output:
PHP Notice: Undefined index: HTTP_HOST in script.php
You could force the variable to exist from the command line, like this:
HTTP_HOST=example.com php -f script.php
Related
I have a php script which runs inside a docker (The php version is 7.2.34 on orcalelinux. ) it uses dns_get_records to fetch spf records for domains. For one particular domain it throws a warning:
Warning dns_get_record(): a temporary server error has occurred on line 7
and returns blank result.
I tried to run same script on php:7.2-fpm-alpine the result is same but a different warning:
Warning: dns_get_record(): Unable to parse DNS data received on line 7
But When I run the script on my wsl linux (Ubuntu with php version 7.2.34) the script executes without warning and returns valid result for same domain
Why is same php function behaving differently on three different environment, and how it can be fixed?
My host operating system is windows 11
Here is php script:
<?php
/* do some stuff*/
$spf = dns_get_record('somedomain',DNS_TXT);
print("---------------------------------SMC SPF record---------------------------------\n");
print("\n$spf\n");
print("---------------------------------SMC SPF record---------------------------------\n");
?>
I cannot expose domain name due to privacy issue.
After much research I found that docker from windows is messing up the name servers in the container so the domain name was not able to get resolved properly hence the temporary error. so I had to edit /etc/resolve.conf in my container to
1.1.1.1
and it started working properly.
I still face issues with curl based APIs in the container so I have decided to run docker inside wsl2 instead.
MongoDB is not giving off any error when trying to run through the browser,
gives a 500 internal server error.
Things I have tried:
checking php modules to make sure its running, and it is.
checked to see if it ran internal from within the server command line
"php myfile.php" and it works
Server has a domain name using an SSL, so its https:
I have tried catching the error but that also does no good tried couple of ways with no luck.
Finally caught an error which makes no sense since the new Mongo driver is loaded, as it works when I run the file directly from console as apose to browser
'MongoDB\Driver\Manager' not found in httpdocs/vendor/mongodb/mongodb/src/Client.php on line 87
To compile PHP 7.1.X on Windows I use steps written here:
https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2
When I try to update dependencies with following command:
phpsdk_deps -u
I get following error:
D:\php-sdk2\php-sdk-binary-tools\phpdev\vc14\x64_71_2\php-7.1.15-src
$ phpsdk_deps -u
Fatal error: Uncaught SDK\Exception: Failed to fetch supported
branches
This is happening for almost two weeks now.
You're having network trouble.
If you open up the Config.php file at this line, you'll see that the Config tries to load the URI https://windows.php.net/downloads/php-sdk/deps/series/, and pick the correct txt file from there, in order to download the right dependencies. The exception you get means that this cannot be properly fetched.
The solution in my case was to use the company proxy (command line wasn't using it, so it cannot properly resolve & reach the above URL, and so the Config.php gets an empty response). How to do so might change depending on the network settings you use. In my case, I simply visited the URL above in Firefox (which is properly configured by the company), opened up the network pannel, get the IP of the website from there (which is actually the IP of the proxy Firefox was told to use by the company settings), and add the IP hostname entry in my host file (C:\Windows\System32\Drivers\etc\host) so it looks like 10.1.2.3 windows.php.net
Then I rerun the Config script, and boom, it managed to retrieve the txt files and the dependencies.
Another solution can be to retrieve all the dependencies listed in the txt file that corresponds to your setup, but it's a bit tedious...
I can execute my php scrape file by typing in the address bar:
domain.com/scrape.php
However, I try to use cron job on my shared server on host gator by this command:
/usr/bin/php-cli public_html/scrape.php
I got this error message:
Fatal error: Call to undefined function GuzzleHttp\Handler\curl_reset() in /home4/username/public_html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 78
I already update my php version to stable 5.6 or even 5.7 version also same error. I think that it should not be php version error because I still can execute the file from browser right ?
Also I cannot reboot server Apache because hostgator support said they cannot reboot it until the server is totally down...
Any help please ! Thank you !
I ran into this problem last week on my own server. As it turned out, my browser was looking at one installation of PHP and cron was looking at a 2nd installation of PHP. One way to check is to run a PHP script through your browser that executes phpinfo(). That will tell you what the browser is running. Have cron do the same and save the results. Compare the two and make sure they're pointing to the same installation of PHP. Don't just check versions. Check install paths and loaded modules. Cheers.
I wrote a PHP script to run as a cron job and it wasn't running. The script worked fine in the browser, but I discovered when I ran it from the command line that I got this error:
Warning: oci_connect(): ORA-12154: TNS:could not resolve the connect identifier specified in /usr/apps/webdata/cron/PropogateDB.php on line 190
The line in question is:
$conn_NRB = oci_connect($user, $pass, "nrb.njbbnrbpd1");
As I said this script works fine in the browser.
I did some digging around and found the configuration settings for the database. I then tried this:
$conn_NRB = oci_connect($user, $pass, "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=nrb)))");
With this code both the command line and the browser give me this error:
Warning: oci_connect() [function.oci-connect]: ORA-01017: invalid username/password; logon denied in /usr/apps/webdata/cron/PropogateDB.php on line 191
As far as I know there are no other usernames and passwords that I can use. (I'm trying to verify that now.)
I searched around on this site and discovered someone else with a similar problem, although his problem was reversed, and his cause was that the command line and the browser pointed to two different php.ini files. I just confirmed that both the browser and the command line invoke the same php.ini file. They both point to:
Configuration File (php.ini) Path => /usr/local/php/lib
Is there any other reason why a script would work in the browser but fail in the command line? I'm relatively new to Oracle SQL and I don't have direct access to the database so I'm not sure where to go from here.
Thanks.
The 'EasyConnect' string
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=nrb)))
refers to localhost. 'In the browser' likely means: on the server (where the PHP script executes).
Unless you run the test on the command - line of the same server, you should change the connect string to refer to the Database server (which might be simply the host name of your web-server).
Beware of firewall restrictions that may come in the way. Prefer to use your company's tnsnames.ora to resolve database instances identifiers to their connect strings, if possible.