Home » Mail » Mail » Bug #3301
Mail can not be sent from CLI
Details
| Submitted | 2005-01-26 15:46 UTC |
|---|---|
| From | tchoudinov at yahoo dot com |
| Status | Bogus |
| Package | |
| PHP Version | 4.3.9 |
| OS | Windows2000 server SP4 |
| Roadmaps | (Not assigned) |
Comments
[2005-01-26 15:46 UTC] tchoudinov at yahoo dot com
Description:
------------
When using Mail_SMTP in command line environment class does not send mails at all. Send() function reports
"unable to authenticate to smtp server"
And a couple of notices:
Notice: Array to string conversion in C:\php\pear\Net\SMTP.php on line 365
Notice: Array to string conversion in C:\php\pear\Net\SMTP.php on line 363
The same script in WEB environment (either Apache or IIS) works just fine.
Reproduce code:
---------------
$recipients = 'tchoudinov@yahoo.com';
$headers['From'] = 'mikhail@adstate.com';
$headers['To'] = 'tchoudinov@yahoo.com';
$headers['Subject'] = 'Test message YY';
$body = 'Test message BB';
//fill an array with parameters
$params["host"] = MAIL_SMTP_HOST; //The server to connect.
$params["port"] = MAIL_SMTP_PORT; //The port to connect.
$params["auth"] = MAIL_SMTP_AUTH; //Whether or not to use SMTP authentication.
$params["username"] = MAIL_SMTP_USERNAME; //The username to use for SMTP authentication.
$params["password"] = MAIL_SMTP_PASSWORD; //The password to use for SMTP authenticat
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('smtp', $params);
$Result = $mail_object->send($recipients, $headers, $body);
echo($Result->getMessage());
Expected result:
----------------
We run the script from command line, but mail must be sent.
Actual result:
--------------
Script repotrs about errors to command line:
Notice: Array to string conversion in C:\php\pear\Net\SMTP.php on line 363
Notice: Array to string conversion in C:\php\pear\Net\SMTP.php on line 365
unable to authenticate to smtp server
[2005-01-26 16:34 UTC] tchoudinov at yahoo dot com
BTW I have Zend engine installed. May this is the problem.
PHP 4.3.9 (cli) (built: Sep 21 2004 14:04:30)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
with Zend Extension Manager v1.0.4, Copyright (c) 2003-2004, by Zend Technologies
with Zend Optimizer v2.5.5, Copyright (c) 1998-2004, by Zend Technologies
with Zend Debugger v3.5.2, Copyright (c) 1999-2004, by Zend Technologies
[2005-01-26 17:41 UTC] tchoudinov at yahoo dot com
Well. I have found the problem and how to solve it after a couple of hours.
The problem is Zend Optimizer.
The problem is "Array to string conversion"
If Optimizer is working on web server then simple code like this generates is a cause of errors in CLI mode:
---------------------------
$array = array();
$array[] = "string_array";
foreach ($array as $element) {
//$verb = strtok($element, ' '); //line like this generates a notice
var_dump($element);
}
---------------------------
Try this code in CLI and you will see a really strange result:
array(2) {
[0]=>
string(12) "string_array"
[1]=>
int(0)
}
Instead just string(12) "string_array".
Disable Optimizer and everything goes fine again!
To disable it comment out the line in php.ini
;zend_extension_manager.optimizer_ts="C:\Program Files\Zend\lib\Optimizer-2.5.5"
Just modification of optimization level zend_optimizer.optimization_level = 0
does not help.