0

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

1
  • 1
    It's likely derived from SERVER_NAME (hence empty on CLI). Though there's certainly a eloh property for PHPMailer. Commented Aug 15, 2018 at 11:36

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! It is working. I added $mail->Hostname in the script and mails are sent.
0

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

2 Comments

While it's true that that can be a source of the HELO host name, and providing one as you suggest may work, PHPMailer checks that it exists before trying to use it, so you won't get an error like that from PHPMailer.
Hi. Tried because seems to be a good solution but Synchro is right. No errors or warnings are echo and HTTP_HOST varable is not set. it does not work :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.