简体   繁体   中英

phpmailer - error when run from command line with php

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM