Jump to content

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


97s
 Share

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

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
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...

Link to comment
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.!

Link to comment
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.

Link to comment
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 ;)

Link to comment
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
Link to comment
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
Link to comment
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
 Share

×
×
  • Create New...