I have many different templates for sending emails!
So I made a php file (lets call it send.php) which I want to "call" with file_get_contents and some parameters (which decide which template should be used) from another File like finish.php!
The different Paths:
templates ("/phpmailer/templates/")
send.php ("/phpmailer/send.php")
finish.php ("/courses/finish.php")
The working Link itself looks something like this:
http://www.myadress.at/phpmailer/send.php?template=booking&email=bla#bla.at&name=Christopher
Inside the send.php I check if the template exists, if YES then the Mail will be sent!
if (file_exists(dirname(__FILE__)."/templates/".$template.".php") AND isset($email)) {
$mail->msgHTML(file_get_contents('https://www.myadress.at/phpmailer/templates/'.$template.'.php?'.$parameter.''), dirname(__FILE__));
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
else
{
ERROR
}
Now when somebody books a course or something, after filling out the signup-form, I want to send an Confirmation Email from the file, the person is landing after the form (finish.php)
My finish.php file hast just a file_get_contents with the Path to my send.php file:
$sendmail= file_get_contents("https://www.myadress.at/phpmailer/send.php?template=booking-confirmation&email=".urlencode($email)."");
Now the problem is, when trying to use it from finish.php with file_get_contents, he says the Template doesnt exist... When copying the same link to firefox, everything works.. The name of the template is right!
I've tried the following things:
(file_exists(dirname(__FILE__)."/templates/".$template.".php") - with dirname
(file_exists("/templates/".$template.".php") - the normal path
(file_exists("/phpmailer/templates/".$template.".php") - full path
(file_exists("http://www.myadress.at/phpmailer/templates/".$template.".php") - normal url
Pleaaase help me ^^ Maybe this isnt possible haha
Okay, now everything works fine!
The problem was caused by either by some spaces in the url or because I didn't urlencode every single variable..
ahhhh so many time!
Related
I'm experimenting with SSR since I've never touched the subject before and want to learn more about it. I've built a simple SSR and it works fine, except when I add some variables in the mix.
This works fine:
<span>msg: hello</span>
This cast an error:
const txt = 'hello';
...
<span>msg: {txt}</span>
Warning: Text content did not match. Server: "msg: hello" Client: "msg: "
If I check the doc request this is what I get from localhost:
<span>msg: hello</span>
and when I inspect element:
<span>
"msg: "
"hello"
</span>
My initial thinking is that the hydration does not read the next line, and just see "msg: ", even tho, it looks fine in the dom and all the data is correct.
I can, however make it work with a templatestring <span>{`msg: $txt}`}</span>
but I have several cases where I check what to print with a function.
Anyone got more information on this one, how can I make React hydration to be more open minded and check for the next line?
check if you use renderToString, and not renderToStaticMarkup.
Similar problem: https://lihautan.com/hydrating-text-content/
I'm trying to get Caddy server to display a file that is kind of dynamic (assigned to a variable). I find the official documentation a bit opaque and searching Internets doesn't return much info either.
My example Caddyfile config:
example.com {
route / {
# own plugin that adds custom headers to the request
my_plugin do_something
map {header.something} {my_file} {
x "x.html"
y "y.html"
default "404.html"
}
file_server {
browse {my_file}
}
}
}
So the idea is Caddy displays "y.html" template if the request contains "something" with value "y". You get the picture.
However Caddy will complain with:
http.log.error parsing browse template: parsing browse template file: open {my_file}: no such file or directory
Looks like it takes the "{my_file}" in literal matters(!).
How does one gets this done in Caddy?
N.B
Other examples such as redir {my_file} work and redirect to "example.com/y.html".
Or is there better way in general to display a template "from a variable" ?
templates {my_file} does not work.
Okay, I figured it out. Eventually.
Simple yet not-so-obvious syntax:
*.example.com {
map {labels.2} {my_file} {
x "x.html"
default "404.html"
}
root * tmpl
file_server
templates
try_files {my_file}
}
So if the domain is x.example.com it will then render the x.html template located in current working directory's tmpl folder. The templates directive is only needed if the template(s) contain any functions/actions (e.g. include).
For a long time, I've had an action that returned
return RedirectToAction("Index","Vendor");
and it worked as expected. At the completion of this function, my Index function was called.
However, lately it stopped working. That same line of code now directs the browser to the url localhost:67676/Vendor/, my Index() action is never called and the page displays:
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
However, if i add a forward slash to the method parameters like
return RedirectToAction("/Index","Vendor");
Everything works as expected and the Index function is called.
Any idea why I need to use "/Index" now but "Index" worked before
The error means that you have a folder in your app named Vendor and the url is trying to navigate to that folder rather than your VendorController. To solve the problem, rename the folder so that it does not match a controller name.
To understand what is happening behind the scenes,
return RedirectToAction("Index","Vendor"); internally looks at your route definitions for a match, and it matches your default route which has defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }. Because you pass "Vendor" as the controller, which does not match default, the first segment of the url becomes Vendor. And because your pass "Index" as the action, it matches the route, so no additional segment is added (its not required). The final url becomes localhost:67676/Vendor which matches your folder (hence the error).
When you used return RedirectToAction("/Index","Vendor");, your passing "/Index" which does not match the default action ("/Index" != "Index") so it generates a 2nd segment in the url which now becomes localhost:67676/Vendor/Index which will hit the controller because you don't (and could not) have a folder named "Vendor/Index"
It's a little late, but I'm posting it under this thread because I ran into the same problem. If there is a folder with the same name as Controller in your project file, you are encountering this problem.
Example;
VendorController -
Vendor (Folder Name)
I encountered this problem because of the wrong path I wrote when I wanted to create a new folder to save an image file.
Be careful when creating "Server.MapPath".
This is probably a stupid one but I have tried all the things I can think of. I am currently getting the below error on my client side script when I try and execute it.
Error: ReferenceError acvt_serialNumber_saveRecord is not defined
On the Script record in Netsuite I have set the saveRecord function as follows:
acvt_serialNumber_saveRecord
The code in the file is:
function acvt_serialNumber_saveRecord(){
/**do stuff */
}
I have reuploaded to code to make sure the right version was in NetSuite. I have added one character to both the script fn name and the fn name on the Script record (as a shot in the dark). I have seen in the Javascript console at runtime that the correct code is in there and I can see the exact function name (I did a ctrl+f for the "undefined" function in the code in the console to make sure spelling was all the same).
NOTHING has worked. I had this code working earlier, but the changes I made were not to this function at all.
Any help is appreciated
Another thing to check is the code that you recently changed. In particular, check for a hanging comma. IE:
var someObj = {
someProp:'somevalue',
};
The comma at the end of 'somevalue' will cause the script to fail, throwing 'undefined' errors.
Have you tried deleting the Script record in NetSuite and re-creating it?
Do you have any library included for that Client Script in netsuite ?
Provide a screen shot of your Netsuite script page
I encounter similar problem like this before, but it was because i called a function which is inside a library file
Thanks
I'm trying to implement a cron job in my wordpress blog. I want to do this stuff in a plugin, for testing I'm trying to write in one file some log information every 10 minutes, for do that I wrote this code (PHP):
add_filter( 'cron_schedules', 'ten_minute_prefix' );
function ten_minute_prefix( $schedules )
{
$schedules['tenmins'] = array(
'interval' => 600,
'display' => __( '10 minutes' ),
);
return $schedules;
}
//This must be here always
add_action('my_task_hook', 'foo_task');
function foo_task()
{
file_put_contents('data.txt', date("Y-m-d H:i:s") . "task do it\r\n", FILE_APPEND);
}
//This is executing in my plugin page in tools section
function myplugin()
{
//For checking permissions
file_put_contents('data.txt', date("Y-m-d H:i:s") . "Task begin\r\n", FILE_APPEND);
wp_schedule_event( time(), 'tenmins', 'my_task_hook' ); // hourly, daily and twicedaily
echo "SCHEDULE ACTION";
...
}
For checking that i have created really the cron job, i using for example this plugin http://wordpress.org/extend/plugins/cron-view/. This plugin says me this "Entry #10: my_task_hook √ action exists".
But nothing is happening, the file is not written, what is the problem?
Edit:
I have added one line in myplugin function for see if i have permission for writing files. In fact, i have got permissions, a data.txt file is created in wp-admin/ folder.
Edit2:
I just to understand the cron jobs in wordpress!
Cron in wordpress is not a real cron, it only fires when any user opens the webpage, if no one opens the page, the process won't fire. So, if a blog has not visitors, cron jobs dont work.
Please, correct me if i am in a mistake.
It could be because you don't have write permissions to write to the folder where data.txt is in. As you haven't explicitly defined which folder to write to, it will write to the folder your PHP file is in.
1) right. check is your directory writable...
if (is_writable(dirname(__FILE__))){
file_put_contents(dirname(__FILE__).'/data.txt', date("Y-m-d H:i:s") . "task do it\r\n", FILE_APPEND);
} else {
mail('yourmail#example.com', 'oops!', 'error writing');
}
2) where is your cron scheldule activated?
add_action('activate_' . __FILE__, 'plugin_activate_demo'));
add_action('deactivate_' .__FILE__, 'plugin_deactivate_demo'));
function plugin_activate_demo(){
wp_schedule_event( time(), 'tenmins', 'my_task_hook' );
}
function plugin_deactivate_demo(){
wp_clear_scheduled_hook('my_task_hook' );
}
3) almost imposible situation which i got on work - Check do you have working cron... simple by adding mail or something like that to your hook_action code. on some servers due dns problems (many networked servers and url routes issue) server name not responding while http://yourservername.com requested (by wp-cron).