I recently moved to Swiftmailer as people have said good things about it. When I used a documentation on how to set it up, I'm getting a strange error. As if their code is wrong.
The error is showing :
Parse error: syntax error, unexpected '?' in Mailer\classes\Swift\Transport\EsmtpTransport.php on line 211
I haven't modified this file atoll and it's throwing that error.
I'm calling my username and password from my config file giving them a DEFINE PHP function.
My code being used is :
define("AUTHENTICATION_DONOTREDIRECT", 1);
require("../main_config.php");
$site_config = new site_config();
$from = $site_config->grabSiteSettings_manual($con, 'name');
require 'Mailer/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')->setUserName(gmail_mail)->setPassword(gmail_pass);
$swift = Swift_Message::newInstance($transport);
$content = "This is a test message.";
$message = Swift_Message::newInstance("This is a test email")
->setFrom('admin#admin.com')
->setTo('benzahdd55#outlook.com')
->setBody($content,'text/html')
->addPart(strip_tags($content),'text/plain');
$swift->send($message);
$myfile = fopen("loggy.txt", "w");
$txt = "success\n";
fwrite($myfile, $txt);
fclose($myfile);
I believe it's because of the new ?? syntax used in PHP 7. Are you running PHP 5?
You might want to downgrade to an older version or update that line and see if it works.
Related
I been trying for hours to get the name of the public folder on a remote server using an ssh2 connection.
On some servers the public directory is "public_html" but others may be "htdocs".
I don't want to hard code the name in my code, much better to get the correct name from the server. I can't figure out why "pwd" works but $_SERVER array and dirname do not.
I read the documentation at: https://www.php.net/manual/en/function.ssh2-exec.php
There is no place that they describe which PHP commands are supported and which are not supported.
Can someone please explain what I might be doing wrong or what I am missing?
//$stream = ssh2_exec($connection, "pwd;"); // This command works returns /home/username
//$stream = ssh2_exec($connection, "dirname(__DIR__);"); // returns null
$stream = ssh2_exec($connection, "$_SERVER['DOCUMENT_ROOT'];"); // Returns error "Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING)..."
stream_set_blocking( $stream, true );
$remotePublicDirectory = "";
while( $buffer = fread($stream,4096) ){
$remotePublicDirectory .= $buffer;
}
fclose($stream);
$remotePublicDirectory = trim($remotePublicDirectory);
echo '$remotePublicDirectory = ' . $remotePublicDirectory . '<br/>';
I made a script to create a file, it was working fine until i think my host changed the script when I asked them what was wrong with it (I fixed it after but now its not working)
Here is the script:
$rand = substr(md5(microtime()),rand(0,26),5);
$seed = str_split('abcdefghijklmnopqrstuvwxyz'
.'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
.'0123456789!##$%^&*()' . 'ǀǁǂǃDŽDždžLJLjljNJNjnjǍǎǏ01D0ǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟ01E0ǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯ01F0ǰDZDzdzǴǵǶǷǸǹǺǻǼǽǾǿ
0200ȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏ0210ȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟ0220ȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯ0230ȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿ0240ɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏ0250ɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟ0260ɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯ0270ɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿ0280ʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏ0290ʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟ02A0ʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯ02B0ʰʱʲʳʴʵʶʷʸʹʺʻʼʽʾʿ02C0ˀˁ˂˃˄˅ˆˇˈˉˊˋˌˍˎˏ02D0ːˑ˒˓˔˕˖˗˘˙˚˛˜˝˞˟02E0ˠˡˢˣˤ˥˦˧˨˩˪˫ˬ˭ˮ˯02F0˰˱˲˳˴˵˶˷˸˹˺˻˼˽˾˿0300̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏0310̛̖̗̘̙̜̝̞̟̐̑̒̓̔̕̚0320̡̢̧̨̠̣̤̥̦̩̪̫̬̭̮̯0330̴̵̶̷̸̰̱̲̳̹̺̻̼̽̾̿0340͇͈͉͍͎̀́͂̓̈́͆͊͋͌ͅ͏0350͓͔͕͖͙͚͐͑͒͗͛͘͜͟͝͞0360ͣͤͥͦͧͨͩͪͫͬͭͮͯ͢͠͡0370ͰͱͲͳʹ͵Ͷͷͺͻͼͽ;Ϳ0380΄΅Ά·ΈΉΊΌΎΏ0390ΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟ03A0ΠΡΣΤΥΦΧΨΩΪΫάέήί03B0ΰαβγδεζηθικλμνξο03C0πρςστυφχψωϊϋόύώϏ03D0ϐϑϒϓϔϕϖϗϘϙϚϛϜϝϞϟ03E0ϠϡϢϣϤϥϦϧϨϩϪϫϬϭϮϯ03F0ϰϱϲϳϴϵ϶ϷϸϹϺϻϼϽϾϿ
'); // and any other characters
shuffle($seed); // probably optional since array_is randomized; this may be redundant
$rand = '';
foreach (array_rand($seed, 50) as $k) $rand .= $seed[$k];
$current = "";
fputs($rand, "[Server]: Welcome To Your New Chat Server");
echo $rand;
Its meant to create a random file and show the user the name of that file
I always get an error:
ec-2017 08:52:43 UTC] PHP Warning: fputs() expects parameter 1 to be
resource, string given in /public_html/rechat/nokeep.php
fputs is expecting a resource ( as the error points out) this should be the handle from fopen()...
$fh = fopen($rand, 'w');
fputs($fh, "[Server]: Welcome To Your New Chat Server");
fclose($fh);
You could alternatively use file_put_contents() which would do this all in one step...
file_put_contents($rand, "[Server]: Welcome To Your New Chat Server");
I am creating a log file for all api call in my application which is written in php (Symfony).
While creating log file I have used "\n" as new line characters but it's not working.
my code is -
$log = "\n Account: ".$Account."---ID: ".$ID;
$log .= "\n Params: ".$params."\n";
$log .= "\n response: ".$response."\n";
It gives me out put in one line, I also tried "\r\n" and "PHP_EOL" but it doesn't works.
How can I able to fix this issue?
Thanks
I think you should replace \n with <br>, but without space in the brackets
Below should work. And I am using this on my all projects to find the error
$contents = file_get_contents('text.txt'); // TO LOAD THE EXISTING CONTENTS OF ERROR LOG FILE
$contents .= PHP_EOL."\n Account: ".$Account."---ID: ".$ID; // CONCAT. ACCOUNT NUMBER
$contents .= PHP_EOL."\n Params: ".$params."\n"; // CONCAT. PARAMS
$contents .= PHP_EOL."\n response: ".$response."\n"; // CONCAT. RESPONSE
file_put_contents('text.txt', $contents, FILE_APPEND); // WRITING ENIRE LOG BACK INTO LOG FILE
I have the following code which works fine until I try to include an external PHP file which is in the same directory.
class.foo.php permission level 777. Parent directory permission set to 777
In the delivery fail response I get: PHP Fatal error: Class 'foo' not found in /home/myname/public_html/pipemail/pipemail.php on line 49
My code is:
#!/usr/local/bin/php -q
<?php
require_once('./class.foo.php');
//Listen to incoming e-mails
$sock = fopen ("php://stdin", 'r');
$email = '';
//Read e-mail into buffer
while (!feof($sock))
{
$email .= fread($sock, 1024);
}
//Close socket
fclose($sock);
//$email .= 'this is a test';
$foo = new foo();
?>
I have tried
require_once('/class.foo.php');
require_once('/home/myname/public_html/pipemail/class.foo.php');
Any help is appreciated.
Thanks in advance
Change to require'/home/myname/public_html/pipemail/foo.php';
it looks like this :
<?php require'/home/myname/public_html/pipemail/foo.php';
.....
.....
.....
?>
Maybe this works:
<?php
require __DIR__ . "/class.foo.php"; // PHP >= 5.3
require dirname(__FILE__) . "/class.foo.php"; // PHP < 5.3
?>
I have a script that reads emails (with attachments) from a pipe and I'm trying to save the attachment(s) to disk for further processing. I've cobbled together some code from a few sites and for the life of me I cannot get the files to save. I'm using 777 as the chmod value so permissions don't seem to be a problem but I wanted to know if maybe I'm limited to certain PHP commands when using the command line processor rather than the browser. Also, I've even hardcoded the "include" directories in the event the file is not executed from the directory where it is located. Any help would be greatly appreciated!
#!/usr/bin/php
<?php
//debug
#ini_set ("display_errors", "1");
#error_reporting(E_ALL);
include('/var/www/simple_html_dom.php');
//include email parser
require_once('/var/www/rfc822_addresses.php');
require_once('/var/www/mime_parser.php');
// read email in from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
//create the email parser class
$mime=new mime_parser_class;
$mime->ignore_syntax_errors = 1;
$parameters=array(
'Data'=>$email,
);
$mime->Decode($parameters, $decoded);
//---------------------- GET EMAIL HEADER INFO -----------------------//
//get the name and email of the sender
$fromName = $decoded[0]['ExtractedAddresses']['from:'][0]['name'];
$fromEmail = $decoded[0]['ExtractedAddresses']['from:'][0]['address'];
//get the name and email of the recipient
$toEmail = $decoded[0]['ExtractedAddresses']['to:'][0]['address'];
$toName = $decoded[0]['ExtractedAddresses']['to:'][0]['name'];
//get the subject
$subject = $decoded[0]['Headers']['subject:'];
$removeChars = array('<','>');
//get the message id
$messageID = str_replace($removeChars,'',$decoded[0]['Headers']['message-id:']);
//get the reply id
//$replyToID = str_replace($removeChars,'',$decoded[0]['Headers']['in-reply-to:']);
//---------------------- FIND THE BODY -----------------------//
//get the message body
if(substr($decoded[0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Body'])){
$body = $decoded[0]['Body'];
} elseif(substr($decoded[0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Body'])) {
$body = $decoded[0]['Parts'][0]['Body'];
} elseif(substr($decoded[0]['Parts'][0]['Parts'][0]['Headers']['content-type:'],0,strlen('text/plain')) == 'text/plain' && isset($decoded[0]['Parts'][0]['Parts'][0]['Body'])) {
$body = $decoded[0]['Parts'][0]['Parts'][0]['Body'];
}
$my_dir = base64_encode($fromEmail);
shell_exec('mkdir -p /var/www/tmp/' . $my_dir . ' -m 777');
//mkdir($_SERVER['DOCUMENT_ROOT'] . "tmp/" . $my_dir, 0777, true);
$target_path = "var/www/tmp/" . $my_dir;
//chdir($target_path);
//------------------------ ATTACHMENTS ------------------------------------//
//loop through email parts
foreach($decoded[0]['Parts'] as $part){
//check for attachments
if($part['Content-Disposition'] == 'attachment'){
//format file name (change spaces to underscore then remove anything that isn't a letter, number or underscore)
$filename = preg_replace('/[^0-9,a-z,\.,_]*/i','',str_replace(' ','_', $part['FileName']));
// write the data to the file
$fp = fopen($target_path . "/" . $filename, 'w');
$written = fwrite($fp,$part['Body']);
fclose($fp);
//add file to attachments array
$attachments[] = $part['FileName'];
}
}
$html = file_get_html($attachments);
Update: Thanks for the informative response...I've been trying to figure out how to run from the command line. I'm getting some errors now, but they still don't make much sense:
PHP Notice: Undefined index: name in /var/www/catcher.php on line 38
PHP Notice: Undefined index: Content-Disposition in /var/www/catcher.php on line 80
PHP Notice: Undefined index: Content-Disposition in /var/www/catcher.php on line 80
PHP Notice: Undefined variable: attachments in /var/www/catcher.php on line 97
PHP Warning: file_get_contents(): Filename cannot be empty in /var/www/simple_html_dom.php on line 39
I have already specified the full include path to the other files and the smmta user should have read access as the /var/www/ directory is 755.
Using 0777 permissions on the mkdir command in your script does not matter at all if the user that the script is running under cannot write to your target directory. So, if this script is running as used sendmail for example, make sure that this user can write to /var/www/tmp.
Some debugging tips: Get a complete e-mail and save it to a file. Figure out what user this script runs as (e.g. sendmail). Then execute the script manually from the commandline and watch for errors. E.g:
sudo -u sendmail /path/to/script.php < /path/to/saved-email.eml
Make sure you have error reporting turned on etc.
Edit: Looking at the errors you posted, it seems that the mime decoder cannot properly parse your message the way you're expecting it. You appear not to be doing any error checking, so instead you get notices and warnings about undefined indexes.
Check in the input and output of the decoder. Make sure the message is decoded the way you expect it to be.