IMAP: not a valid imap resource - php

I am experiencing problems with IMAP resources in PHP: I the error supplied is not a valid imap resource for the following code:
$imap = imap_open("{"."$host:$port/imap$ssl"."}$folder", $user, $pass);
imap_headers($imap);
$new_emails = imap_search($imap, "UNSEEN");
imap_close($imap);
$counter = $counter+count($new_emails);
I get the following errors:
warning: imap_close(): supplied is not a valid imap resource on line 896.
warning: imap_headers(): supplied is not a valid imap resource on line 892.
warning: imap_search(): supplied is not a valid imap resource on line 894.
Edit
I'm now also getting:
NO IMAP CONNECTION Notice: Undefined variable: imap_connection in /var/www/vhosts/talent.co.uk/httpdocs/intranet/model/helpdesk_finance_admin.php on line 214
Warning: imap_getmailboxes(): supplied argument is not a valid imap resource in /var/www/vhosts/talent.co.uk/httpdocs/intranet/model/helpdesk_finance_admin.php on line 216
Notice: Undefined variable: imap_connection in /var/www/vhosts/talent.co.uk/httpdocs/intranet/model/helpdesk_finance_admin.php on line 220
Warning: imap_headers(): supplied argument is not a valid imap resource in /var/www/vhosts/talent.co.uk/httpdocs/intranet/model/helpdesk_finance_admin.php on line 220
Notice: Undefined variable: imap_connection in /var/www/vhosts/talent.co.uk/httpdocs/intranet/model/helpdesk_finance_admin.php on line 222
Connection failed! Notice: Undefined property: model::$no_mail in /var/www/vhosts/talent.co.uk/httpdocs/intranet/view/helpdesk_finance_admin.php on line 1346
Warning: Invalid argument supplied for foreach() in /var/www/vhosts/talent.co.uk/httpdocs/intranet/view/helpdesk_finance_admin.php on line 1403

Most likely there is an error and imap_open returns FALSE which is not a valid resource to be passed to imap_close.
Always check the results of operations that can fail

The Login details were wrong, so imap couldn't connect succcesfully and that therefore lead to an error code.

try with this syntaxe
{webmail.talent.co.uk:993/imap/ssl/novalidate-cert}INBOX

Related

imap_open authentication failure on localhost

I'm using PHP 7.4.15 and Gmail IMAP to fetch emails from server.
Same credentials work on QA env but failing on my local machine, I'm using the following code:
$username = 'testing+some_email_queue#example.com';
$password = '<some password>';
$imap = imap_open('{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX', $username, $password);
var_dump($imap);
I'm running my code example using the following command: php -f imap.php and output is:
PHP Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX in C:\Projects\<path>\imap.php on line 9
Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX in C:\Projects\<path>\imap.php on line 9
bool(false)
PHP Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
PHP Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
PHP Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
Notice: Unknown: [AUTHENTICATIONFAILED] Invalid credentials (Failure) (errflg=1) in Unknown on line 0
PHP Notice: Unknown: Too many login failures (errflg=2) in Unknown on line 0
Notice: Unknown: Too many login failures (errflg=2) in Unknown on line 0
In my php.ini file imap extension is enabled.
Any idea what might be the reason?

Pear error "XML Extension not found" on Ubuntu 14.04 after installing php-xml & php-xml7.0

I wanna use the pecl command to install redis to my php on Ubuntu 14.04. But my Pear is giving me a list of warnings:
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
Notice: Undefined index: honorsbaseinstall in Role.php on line 173
Notice: Undefined index: installable in Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
Notice: Undefined index: installable in Role.php on line 139
Notice: Undefined index: phpfile in Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
Notice: Undefined index: phpfile in Role.php on line 204
Notice: Undefined index: config_vars in Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
Notice: Undefined index: config_vars in Role.php on line 46
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 249
Warning: Invalid argument supplied for foreach() in /usr/share/php/PEAR/Command.php on line 249
XML Extension not found
Last line gives me this message
XML Extension not found
, although I installed #sudo apt-get install php-xml php7.0-xml. But the same problem still occurs.
What could be the problem?
Install this list and everything will work fine :)
sudo apt-get install php-pear pkg-config libbson-1.0 libmongoc-1.0-0 php-xml php7.0-xml php-dev
On some installations, there is a bug in pecl. Find this line;
exec $PHP -C -n -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d safe_mode=0 -d register_argc_argv="On" $INCDIR/peclcmd.php "$#"
remove the -n
If you want to script it, try:
sed -i "$ s|\-n||g" /usr/bin/pecl
Was Facing this issue, i just needed to install php-xml
sudo apt-get install php-xml
Credits: Taha EL BOUFFI
Full Explanation as to why can be found here
Note: this is not exactly an answer to the original questions, but this might be more relevant now and in the future.
One of the possible reasons for this kind of error in more modern Ubuntu versions (like 20.04) is the possibility of having more than one version of PHP installed in the system.
Even if you install only 7.x version, and 7.x plugins and f.ex. some HTTP server like Apache it does not mean that there won't be another PHP installed. It might be installed either initially (for example in docker base image) or as a dependency of something else.
I've had such a problem in a legacy docker container which used to build and work before.
The solution was to remove PHP 8.x just before PEAR install.
sudo apt-get purge -y `apt list --installed | cut -d/ -f1 | grep php8 | awk '{print $1}' |tr "\n" " "`
or
sudo apt-get purge -y `dpkg -l | grep php8 | awk '{print $2}' |tr "\n" " "`

Composer update doesn't work in my case

I installed Laravel 5.0 at my websites (via FTP). Then I tried to connect via SSH and update using Composer. However I am getting this error. (My PHP is version 5.5, I checked the phpinfo function).
PHP Notice: Undefined index: argv in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 55
PHP Warning: array_shift() expects parameter 1 to be array, null given in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 59
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
PHP Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
[ErrorException]
Invalid argument supplied for foreach()
X-Powered-By: PHP/5.3.28
Content-type: text/html
Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI
Notice: Undefined index: argv in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 55
Warning: array_shift() expects parameter 1 to be array, null given in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 59
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
Warning: Invalid argument supplied for foreach() in phar:///home/cluster-sites/58/kerimcaglar.com/laravel/composer.phar/vendor/symfony/console/Input/ArgvInput.php on line 285
I controlled cli -v , I getting this command not found.
Later I tried below:
$ php -d register_argc_argv=1 "./composer.phar" install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.
Problem 1
- league/flysystem 1.0.16 requires php >=5.4.0 -> your PHP version (5.3.28) or value of "config.platform.php" in composer.json does not satisfy that requirement.
- league/flysystem 1.0.16 requires php >=5.4.0 -> your PHP version (5.3.28) or value of "config.platform.php" in composer.json does not satisfy that requirement.
- Installation request for league/flysystem 1.0.16 -> satisfiable by league/flysystem[1.0.16].
I suspect this is the important error:
Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI
Try which php to see where your PHP binary is pointing, and then locate bin/php to find out what other versions you have your system.
Also note this:
My PHP is version 5.5; I checked the phpinfo function
Something disagrees with you:
X-Powered-By: PHP/5.3.28
Try other copies of your PHP binary, discovered with locate, using the fully-qualified path. For example:
/usr/bin/php55-cli composer.php update
If this host has a 5.5 CGI binary and a 5.3 console binary, it is possible they do not know what they are doing - 5.3 should no longer be supported these days. If you do not have any luck fixing it yourself, create a support ticket and ask for php to invoke the 5.5 console binary from the shell.
Update: following from the conversation in the comments, it looks like the above has fixed one problem and exposed another. The new problem is that your Composer command is getting further, and it is trying to invoke a PHP helper that uses the php binary again. This then causes the original problem (it's the web server binary, and it's 5.3 rather than 5.5).
To resolve this, I suggest you (a) create a local php executable to point to the version you want, and then (b) reset the system path. I would try the following, in your project directory:
ln -s /usr/bin/php55-cli ./php
PATH=. ./php composer.phar update
What this will do is create a symbolic link to the version of PHP that you want, and then reset the system path temporarily to just the current directory.
If this does not fully resolve the issue, you may need to put your symlink in a more permanent place (e.g. ~/bin/php and modify your shell start-up file. Please be willing to play around with this before exclaiming that it does not work - the best way to learn how to do this independently is to try!

I am trying to send email from cPanel using codeigniter but every time I get the error saying connection time out

I have used the following code to send email.
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.sendgrid.net',
'smtp_user' => 'username',
'smtp_pass' => 'password',
'smtp_port' => 587,
'crlf' => "\r\n",
'newline' => "\r\n",
'mailtype' => "html"
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($email);
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($message);
This code works fine in my localhost but every time I run this code from cPanel I get the error saying.
Errors:
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to smtp.sendgrid.net:587 (Connection timed out)
Filename: libraries/Email.php
Line Number: 1689
A PHP Error was encountered
Severity: Warning
Message: fwrite(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1869
A PHP Error was encountered
Severity: Warning
Message: fwrite(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1869
A PHP Error was encountered
Severity: Warning
Message: fwrite(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1869
A PHP Error was encountered
Severity: Warning
Message: fwrite(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1869
A PHP Error was encountered
Severity: Warning
Message: fwrite(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fwrite(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets(): supplied argument is not a valid stream resource
Filename: libraries/Email.php
Line Number: 1869
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home3/pinesof1/public_html/flyannapurna.com/system/core/Exceptions.php:185)
Filename: libraries/Session.php
Line Number: 688
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home3/pinesof1/public_html/flyannapurna.com/system/core/Exceptions.php:185)
Filename: libraries/Session.php
Line Number: 688
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home3/pinesof1/public_html/flyannapurna.com/system/core/Exceptions.php:185)
Filename: libraries/Session.php
Line Number: 688
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home3/pinesof1/public_html/flyannapurna.com/system/core/Exceptions.php:185)
Filename: libraries/Session.php
Line Number: 688
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home3/pinesof1/public_html/flyannapurna.com/system/core/Exceptions.php:185)
Filename: libraries/Session.php
Line Number: 688
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home3/pinesof1/public_html/flyannapurna.com/system/core/Exceptions.php:185)
Filename: helpers/url_helper.php
Line Number: 542
Can anyone tell me what I should do?
Try setting Max Execution time to a larger number, and see if that works for you.
<?php
ini_set('max_execution_time', 108000);
?>
OR
You could change you're php.ini file
I don't know what's not working on your code, but sure, there's a most simple solution that should work everytime, i use it:
$to = "yourTarget#someDomain.com";
$subject = "Your subject";
$message = "<html><body>Your message</body></html>";
$headers = "MIME-Version: 1.0" ."\r\n"
."From: theMailYouWantToUse#domain.com" ."\r\n"
."Content-type:text/html;charset=UTF-8" ."\r\n"
."Reply: reply#yourDomain.com" ."\r\n"
."X-Mailer: PHP/" .phpversion();
$mail_success = mail($to,$subject,$message,$headers);
Note: you need all this headers or the mail is gonna go to junk.
Bonus
I think it's better have a file with your message, and you often have some content to modify. Just use the code bellow before sending:
$message = file_get_contents("file.html");
$message = str_replace("%param1%",$param1,$message);
$message = str_replace("%param2%",$param2,$message);
Very first error Message: fsockopen() [function.fsockopen]: unable to connect to smtp.sendgrid.net:587 (Connection timed out) says a lot about your problem. It means the port 587 is not accessible for you. It may happen by several reasons:
This port is blocked on your server.
Server's IP is blocked on smtp.sendgrid.net (probably your server is in blacklist)
Network problems on your server
As far as I see 587 port is open for me on smtp.sendgrid.net as well as 25 port. Try 25 port also and see if you have the same issue. If you still see this error, ask your hosting company or your system administrator to check servers firewall for 587 port. You can also try to telnet <DOMAIN_NAME> <PORT_NUMBER> to see if you can connect to specific port from your server, this may help a lot to find the answer why this error occurs.

PHP Restler Server 500 Error

I've installed restler using composer. I've set up a virtual host for it. I'm able to go to my localhost in my browser and it shows some informational pages but as soon as I try one of the APIs I get a server 500 error.
My PHP logs say:
Function main
Error Type E_ERROR
Source File /public/examples/_001_helloworld/index.php : 18
Error String Class 'Luracast\Restler\Restler' not found
I'm using the example code straight out of the project. It looks like it has the require_once '../../../vendor/restler.php' and it seems to still have 500 errors.
I'm using PHP 5.4.16 on a Mac.
Update
Here are all of my logs:
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: include(/Users/ChrisLondon/composer/autoload_classmap.php): failed to open stream: No such file or directory in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 432
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: include(): Failed opening '/Users/ChrisLondon/composer/autoload_classmap.php' for inclusion (include_path='.:/usr/local/zend/share/ZendFramework/library:/usr/local/zend/share/pear:/opt/local/lib/php') in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 432
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: include(/Users/ChrisLondon/composer/autoload_namespaces.php): failed to open stream: No such file or directory in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 432
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: include(): Failed opening '/Users/ChrisLondon/composer/autoload_namespaces.php' for inclusion (include_path='.:/usr/local/zend/share/ZendFramework/library:/usr/local/zend/share/pear:/opt/local/lib/php') in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 432
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: array_values() expects parameter 1 to be array, boolean given in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 154
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: array_merge(): Argument #2 is not an array in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 155
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: array_merge(): Argument #1 is not an array in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 155
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: array_map(): Argument #2 should be an array in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 166
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: array_filter() expects parameter 1 to be array, null given in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 166
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: natsort() expects parameter 1 to be array, null given in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 167
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: array_unique() expects parameter 1 to be array, null given in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 170
[05-Sep-2013 17:05:09 America/Denver] PHP Warning: implode(): Invalid arguments passed in /Users/ChrisLondon/personal/SuperfyMe/vendor/Luracast/Restler/AutoLoader.php on line 170
[05-Sep-2013 17:05:09 America/Denver] PHP Fatal error: Class 'Luracast\Restler\Restler' not found in /Users/ChrisLondon/personal/SuperfyMe/public/examples/_001_helloworld/index.php on line 19
It seems like it's trying to find the autoload class here: /Users/ChrisLondon/composer/autoload_classmap.php but the file is actually here: /Users/ChrisLondon/personal/SuperfyMe/vendor/composer/autoload_classmap.php
Solved my issue.
It turns out because I have a folder named composer/ that happens to be two folders up from where the Restler app sits it ruins the Restler autoloader. To solve the issue one needs to do one of the following:
1) Don't have any folder named composer/ two folders up from where the Restler app resides
2) Modify the Restler autoloader to skip the folder (at the time of this post you could comment out line 138 of /vendor/Luracast/Restler/Autoloader.php)
A more elegant solution has been proposed by me on GitHub:
Issue: https://github.com/Luracast/Restler/issues/195
Pull Request: https://github.com/Luracast/Restler/pull/196
By the time someone else finds this post hopefully the issue will be resolved in future versions of Restler.

Categories