PHP MAILER Warning: trim() expects parameter 1 to be string - php

am using phpmailer to send mail, which is sending mail but i keep getting this error, any help is appreciated,
Warning: trim() expects parameter 1 to be string, object given in
........../mail/class.phpmailer.php on line
773
Warning: trim() expects parameter 1 to be string, object given in
........../mail/class.phpmailer.php on line
773
Warning: trim() expects parameter 1 to be string, object given in
........../mail/class.phpmailer.php on line
773
here is line 771 downwards
771 protected function addOrEnqueueAnAddress($kind, $address, $name)
772 {
773 $address = trim($address);
774 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
775 if (($pos = strrpos($address, '#')) === false) {
776 // At-sign is misssing.
777 $error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address";
778 $this->setError($error_message);
779 $this->edebug($error_message);
780 if ($this->exceptions) {
781 throw new phpmailerException($error_message);
782 }
783 return false;
784 }

Related

how to fix Issue with codeigniter 4 after pushing to live server

After building my website on localhost it works fine but when I launched it to a live server, the homepage displays, and few other pages as others couldn't. Please can someone help me out?
I got this error
rewind($this->fileHandle);
207 }
208
209 $session_data = '';
210 clearstatcache(); // Address https://github.com/codeigniter4/CodeIgniter4/issues/2056
211 for ($read = 0, $length = filesize($this->filePath . $sessionID); $read < $length; $read += strlen($buffer))
212 {
213 if (($buffer = fread($this->fileHandle, $length - $read)) === false)
214 {
215 break;
216 }
217
218 $session_data .= $buffer;
219 }
and this
Fatal error: Uncaught ErrorException: Unknown: Cannot call session save handler in a recursive manner in Unknown:0 Stack trace: #0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'Unknown: Cannot...', 'Unknown', 0, NULL) #1 {main} thrown in Unknown on line 0

fwrite() expects parameter 1 to be resource, string given in c://

I am using latest version of php.. and i stuck on this error
Warning: fwrite() expects parameter 1 to be resource, string given in c:\ this error shows me 6 times
Warning: fclose() expects parameter 1 to be resource, string given in // this error reapeat only one time.
I am trying to get last id of last line but i am facing that error.. here is my php code :
<?php
include_once('../../fucrenzione.php');
/*
$codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$codeAlphabet.= "abcdefghijklmnopqrstuvwxyz";
$codeAlphabet.= "0123456789";*/
$filename ="data.txt" or die("Unable to open file!");
$line="";
fopen($filename, 'a+');
for($i=0;$i<=5;$i++ ){
$va=rand(1,20);
$re= rand(2,50);
$data = [
'val1' => $va,
'val2' => $re,
'body' => getToken(10),
'Id'=> $i,
'timestamp' => time()
];
/* echo "<pre>".*/$line = serialize($data);
$line .= "\n";
fwrite($filename, $line);
}
fclose($filename);
?>
I tried to use also fputs() but i still get that error.
The error tells you the issue. fopen() returns a resource:
$handle = fopen($filename, 'a+');
Then fwrite() expects the first argument to be that resource:
fwrite($handle, $line);
Also, I think the or die("Unable to open file!"); would be better on the fopen() line rather than the assignment line.

Invalid argument supplied for foreach() - can't loop through two arrays

My code should convert "defindex" from array_inv into "item_name" from array_schema:
<?php
$apikey = "X";
$steamid = $steamprofile['steamid'];
$url_inv = "http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=". $apikey . "&steamid=" . $steamid . "&format=json";
$url_schema = "http://git.optf2.com/schema-tracking/plain/Counter%20Strike%20Global%20Offensive%20Schema?h=counterstrikeglobaloffensive";
$array_inv_raw = file_get_contents($url_inv);
$array_schema_raw = file_get_contents($url_schema);
$array_inv = json_decode($array_inv_raw,true);
$array_schema = json_decode($array_schema_raw,true);
foreach($array_inv['result']['items'] as $item){
foreach($array_schema['result']['items'] as $schemaItem){
if($item['defindex'] == $schemaItem['defindex']){
echo $schemaItem['item_name'].'<br />';
break;
}
}
}
?>
But it's resulting in these errors:
Warning:
file_get_contents(http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=x&steamid=76561198037897388&format=json):
failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in
/home/kartm/public_html/scripts/inv.php on line 6
Warning: Invalid argument supplied for foreach() in
/home/kartm/public_html/scripts/inv.php on line 12
The urls:
array_inv
array_schema
I can't find any mistakes. Can you tell me what's wrong with this code?
These errors were caused by a typo in a url:
http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?language=en?key=x&steamid=76561198037897388&format=json
It should have been & key=x instead of ?key=x.
file_get_contents couldn't fetch the url, thus the foreach had an invalid, empty argument.

Yii: How to create yii application object in another php application?

I want to use Yii functions in another open source project (moodle, joomla, ...) So I can benefit Yii powerful models.
I put following code in one of the files (ROOT/course/edit.php):
$yii = dirname(__FILE__) . '/../mws/framework/yii.php';
$config = dirname(__FILE__) . '/../mws/protected/config/main.php';
defined('YII_DEBUG') or define('YII_DEBUG', TRUE);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
require_once($yii);
Yii::createWebApplication($config);
But I get following error:
PHP warning include(edit.php.php) [function.include]: failed to open stream:
No such file or directory
D:\WAMP\www\millms\mws\framework\YiiBase.php(427) 415
{ 416 include($classFile); 417
if(YII_DEBUG && basename(realpath($classFile))!==$className.'.php')
418 throw new
CException(Yii::t('yii','Class name "{class}" does not match class
file "{file}".', array( 419
'{class}'=>$className, 420
'{file}'=>$classFile, 421 )));
422 break; 423
} 424 } 425 } 426
else 427 include($className.'.php'); 428
} 429 else // class name with namespace in PHP 5.3
430 { 431
$namespace=str_replace('\','.',ltrim($className,'\')); 432
if(($path=self::getPathOfAlias($namespace))!==false) 433
include($path.'.php'); 434 else 435
return false; 436 } 437 return
class_exists($className,false) || interface_exists($className,false);
438 } 439 return true; Stack Trace
#0 + D:\WAMP\www\millms\mws\framework\YiiBase.php(427):
YiiBase::autoload() #1 unknown(0):
YiiBase::autoload("edit.php") #2 unknown(0):
spl_autoload_call("edit.php") #3 –
D:\WAMP\www\millms\lib\formslib.php(831): is_a("edit.php",
"moodle_url") 826 static $formcounter = 1; 827
828 HTML_Common::HTML_Common($attributes); 829
$target = empty($target) ? array() : array('target' => $target);
830 $this->_formName = $formName; 831 if
(is_a($action, 'moodle_url')){ 832 $this->_pageparams
= $action->hidden_params_out(); 833 $action = $action->out(true); 834 } else { 835
$this->_pageparams = ''; 836 } #4 –
D:\WAMP\www\millms\lib\formslib.php(115):
MoodleQuickForm->MoodleQuickForm("course_edit_form", "post",
"edit.php", "", ...) 110 $action =
strip_querystring(qualified_me()); 111 } 112 113
$this->_formname = get_class($this); // '_form' suffix kept in order
to prevent collisions of form id and other element 114
$this->_customdata = $customdata; 115 $this->_form =& new
MoodleQuickForm($this->_formname, $method, $action, $target,
$attributes); 116 if (!$editable){ 117
$this->_form->hardFreeze(); 118 } 119
$this->set_upload_manager(new upload_manager()); 120 #5
– D:\WAMP\www\millms\course\edit.php(448):
moodleform->moodleform("edit.php", array("course" => null, "category"
=> stdClass)) 443 } 444 } 445 446 447 /// first create the form 448 $editform = new
course_edit_form('edit.php', compact('course', 'category')); 449
// now override defaults if course already exists 450 if
(!empty($course)) { 451 $course->enrolpassword =
$course->password; // we need some other name for password field
MDL-9929 452 $editform->set_data($course); 453 }
How I can Create A raw Yii Application Object?

Problem with sprintf error when using S3->copyObject() and filenames with % in them

I am using PHP S3.PHP class to manage files on Amazon S3. I use the copyObject() function to copy files in my S3 bucket. All works great until I meet filenames that need to be urlencoded (I urlencode everything anyway). When a filename ends up with % characters in it the copyObject() function spits the dummy.
for example - the filename 63037_Copy%287%29ofDSC_1337.JPG throws the following error when passed to copyObject() -
Warning: sprintf() [<a href='function.sprintf'>function.sprintf</a>]: Too few arguments in ..... S3.php on line 477
Here's the copyObject function line 477
public static function copyObject($srcBucket, $srcUri, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array()) {
$rest = new S3Request('PUT', $bucket, $uri);
$rest->setHeader('Content-Length', 0);
foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
$rest->setAmzHeader('x-amz-acl', $acl);
$rest->setAmzHeader('x-amz-copy-source', sprintf('/%s/%s', $srcBucket, $srcUri));
if (sizeof($requestHeaders) > 0 || sizeof($metaHeaders) > 0)
$rest->setAmzHeader('x-amz-metadata-directive', 'REPLACE');
$rest = $rest->getResponse();
if ($rest->error === false && $rest->code !== 200)
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
if ($rest->error !== false) {
-------------------------------------------- LINE 477 ----------------------------
**trigger_error(sprintf("S3::copyObject({$srcBucket}, {$srcUri}, {$bucket}, {$uri}): [%s] %s",
$rest->error['code'], $rest->error['message']), E_USER_WARNING);**
-------------------------------------------- LINE 477 ----------------------------
return false;
}
return isset($rest->body->LastModified, $rest->body->ETag) ? array(
'time' => strtotime((string)$rest->body->LastModified),
'hash' => substr((string)$rest->body->ETag, 1, -1)
) : false;
}
Has anyone come across this before? There is absolutely no problem when using filenames which don't change when urlencoded, and Ive already tried removing all whitespace from filenames but wont be able to catch all characters, like brackets which is the problem in the example here. And I dont want to go down that road anyway as I want to keep the filenames as close to the original as possible.
thanks guys
Redo the line this way:
trigger_error("S3::copyObject({$srcBucket}, {$srcUri}, {$bucket}, {$uri}): ". sprintf("[%s] %s",
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
%'s in the first parameter to sprintf are identified as the placeholders for values. Because your filenames are first inserted in the string and that string is then passed to sprintf(), sprintf() mistakenly interprets the %'s in the file names as placeholders.

Categories