Jump to content
Sign in to follow this  
97s

using mail() and creating a mailer.php file. - where in processwire do i put these files?

Recommended Posts

So, I am doing something a bit complex here, but I have it working on a static site. So I know it all works as planned. However I can't get it to work inside of processwire, and I am not sure why.

Let me explain what is going on.

So I have built a template with my form code.

Then I have a js file, that uses AJAX/php to mail me a copy of what the form contained upon submission. This is due to the fact the form is going to a third party processor. They do not send nice pretty copies, but they do send a confirmation, which is enough for me to match them later by hand.

So my issue is lies here:

I have created a template that contains this information, then I have included my javascript in the header.

However, I don't know where to place the mailer.php and the other file that it calls.

I have tried placing them in templates/includes/

then calling them in my javascript like so.

//code

$.post('http://examplesite.com/site/templates/includes/donate_in_memory_mailer.php', $('form#donate').serialize(), function(data){

});

//code

then inside of that donate_in_memory_mailer.php I have an include for another .php file.

I have done it's include similar:

//code

include 'http://examplesite.com/site/templates/includes/memory_mailer.tpl.php';

//code

However, it appears this isn't working. I cannot get it to work, I have even tried putting this folder in my root directory. Does anyone have any ideas. I would assume it wasn't a processwire issue, but when I can make everything work the same exact way on another static site I get confused.

Please I hope this is just a simple fix, its the last part of the first site I have ever built with processwire!

Thanks!!

-Joseph

Share this post


Link to post
Share on other sites

Guys I am just going to use a work around.

I am just going to make a static directory, and then in processwire point my links to the static directory, thus solving my problem for now.

Thanks.

and you can delete/close this, unless someone wants to go crazy and figure it out.

i really appreciate the help so far, ive spent 7 hours on this, and im just tired of trying to figure it out.

Share this post


Link to post
Share on other sites

I'm not sure, but think that you have to make a page for this purpose with a dedicated template and then include your php-script in this tempalate. And call that page from your js. You can use additional URL-segmants or set POST variable to check before running your included script. I think this way it should work.

Share this post


Link to post
Share on other sites

I already have a custom template,

I did away with the .tpl file, made it simpler and its now just 1 php file.

So for example, I should just include the mailer.php code in my example-template.php. Then have my js call, site/templates/example-template.php?

BTW thanks for the help.

Share this post


Link to post
Share on other sites
you have to make a page for this purpose with a dedicated template

I second that. You have to use here the same logic that you use for normal pages. You can't reach the php files in the templates folders by AJAX, the same way you can't from the browser address bar. PW is changing the way that the URLs work so that they mirror the tree that you see on the admin.

EDIT:

So for example, I should just include the mailer.php code in my example-template.php. Then have my js call, site/templates/example.php?

Put your memory_mailer.tpl.php file on the templates folder.

Create a template on the admin pointing to that file (you can keep only the title field).

Create a new page with that template. Lets call it "Mailer", for instance.

Hide the page from visitors on the page settings.

Use the URL http://examplesite.com/mailer/ on your AJAX calls.

I think this should work...

Share this post


Link to post
Share on other sites

after trying my work around, im realizing, that I can't actually do that, because I have to much dynamic content that i have to integrate this into pw some how.. wooo.. atleast ill know more about php and processwire.!

Share this post


Link to post
Share on other sites

diogo,

what exactly do you mean a dedicated template then, I thought I understood what that meant, but maybe I dont.

I have created a make-a-donation.php template, and the content area is static with my form. I think I am getting more confused . heh. just takes time ill figure it out eventually with you all's wonderful help.

Share this post


Link to post
Share on other sites

UPDATE: I think you awesome people have nailed the donkey on the head. I am getting somewhere all of the sudden! Thanks people!

Share this post


Link to post
Share on other sites

I mean that you have to apply here the same logic that you use for pages. Because, unlike what happens with php includes, the javascript doesn't have access to your folder structure.

How do you create pages in PW? You create the page on the tree, and you assign a template to it that is connected to a php file on your templates folder. So, here you have to do the same :)

EDIT: Glad that you are getting into it ;)

Share this post


Link to post
Share on other sites

All things are hard untill they are easy :) Glad you solved this.

Share this post


Link to post
Share on other sites

OK! So I solved everything, and its all working perfectly.

I ended up building one hell of a template page. All the javascript and php is contained in this one template page. The javascript ajax resubmits the information to itself, which clears the form, and spins out the email. The action goes to the payment processor's page.

All of it works beautiful. Thanks for all the advice. I didn't think about just building it all into one template. I am so so at php, very beginner to advanced things. This is my first site with processwire and I love how smooth things are.

  • Like 1

Share this post


Link to post
Share on other sites

Great that everything is working!

Share this post


Link to post
Share on other sites

UPDATE:

The jQuery .post() request broke in IE. IE is picky and has to have a value for the post, it doesn't use the current pages information like all the other browsers did. Thus my solution for a 1 page template did not work.

Instead I did as you all recommended, made two templates, the form template for the public with the javascript included on that page, and some processwire php to get the url of the mailer page. Placed that php echo code inside the post request, then made a new template with the mailer php code. Added that template to processwire and created a page.

IE now works as expected along with all the other browsers.

I just wanted to let others know in case they come upon this same problem.

HIGH FIVE TO PROCESSWIRE & FORUM MEMBERS!

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By a.masca
      Goodmorning everyone,
      sorry for the inconvenience but I have a problem that I can't find in any other post.
      Strange things happen on a site:
      - despite everything being configured correctly (as already done in dozens of other sites) only superusers can create new pages
      - if I insert in a selector "include = all" the result is always 0
      - I should restore a series of pages incorrectly inserted in the trash, but I cannot select them with the selector "status = Trash"
      Some idea?
      Thanks so much for your valuable support.
    • By LAPS
      According to this old post, I'm trying to use the PW cache feature:
      $my_page = $pages->get($pageId); if($my_page->viewable()) { $content = $cache->get("my_page"); if(!$content) { $content = renderCustom($my_page->children); $cache->save('my_page', $content, 3600); } echo $content; } function renderCustom(PageArray $items) { foreach($items as $item) { echo $item->title; // ... heavy content loading } } After loading the page which renders the above code, in the admin I can see something was cached (note: I'm using ClearCacheAdmin) :

      But when I reload the page the cached value seems do not be used and the page loads slowly.
      The result of doing var_dump() is the following:
      var_dump($cache); // return object(ProcessWire\WireCache)#20 (0) { } $content = $cache->get("my_page"); var_dump($content); // return string(0) ""  
      What could be the problem?
    • By LAPS
      Can you confirm that the function renderField for fieldset fields, even having the file /site/templates/fields/fieldName.php or /site/templates/fields/fieldName/$file.php (using $file argument), does not render anything as expected?
      $page->renderField('fieldsetName') // returns nothing ... or am I wrong on something?
    • By LAPS
      Hi there,
      I'm working on an email message template and would like to render a custom one to be sent.
      I tried to use $files->render() this way
      // rendering file e.g. a template file or a hook statement in ready.php $body = $files->render('emails/myfile', array( 'myVar1' => $var1, 'myVar2' => $var2, ... )); but $vars seems to be not accessible from within the rendered file. That is, $vars seems to be not set:
      // rendered file emails/myfile.php $myVar1 = $vars['myVar1']; // is not set $myVar2 = $vars['myVar2']; // is not set ... // is not set How can I get the $vars so to properly render the custom message template for sending the email?
       
      Notes:
      By using $files->include() the $vars is accessible but I cannot use this method because I should retrieve the output $body as a return value for sending the email later. So, I'm still looking to render the custom message using $files->render(). This thread is someway related to this one.
    • By Markus (Blue Tomato)
      I'am working on a migration script from the ImageExtra Module to the new Custom Image Fields feature in ProcessWire.
      I have some problems while setting a field value to the new custom image field. I have set up the custom field and it works correct in the admin panel but not via the API:
      $page->images->my_custom_image_field = "test"; $page->save(); Results into:
      Fatal error: Uncaught ProcessWire\WireException: Item 'my_custom_image_field' set to ProcessWire\Pageimages is not an allowed type in /var/www/html/wire/core/WireArray.php:458
       
       
×
×
  • Create New...