Forums

web2py php mailer

Hi I am trying to use jquery to invoke a php script that sends me an email through a google server when a button is clicked on my website. I am using web2py and it doesn't seem to be working. I have had success with the same script so I know the php is okay. I am wondering if the problem is that maybe python anywhere could be blocking the request? The reason i am wondering this is that after the ajax request goes through it is active, so something is holding it up? Any help would be appreciated. :)

Could it be that google have decided the email send request is suspicious, because they don't recognise our IP address? Take a look at your google account security page, and look for the 'security notifications' bit...

No nothing there, I am assuming its something on my end. thanks for the help! :)

Sounds possible; I assume that the PHP script is running somewhere else (pretty sure we haven't accidentally enabled PHP here ;-) so if it's jQuery from your web app it will go directly to that other place, and PythonAnywhere shouldn't be in the mix anywhere...

Ah that is most likely the problem. I have jquery just invoke the script so its probably trying to run here and thus wont work. Any suggestions on parsing a form and creating an email?

I think web2py has some built-in helpers to do emails? (like this? am not a web2py expert). beyond that, check out our help page on email: https://www.pythonanywhere.com/wiki/SMTPForFreeUsers

The main problem is that you cant really use the web2py mailer with javascript, it seems to be strictly for python. Im trying to parse the javacript forms and then pass the variables via jquery into the script. Its much easier to do this though with php then python.

Oh, right. The standard approach would be to get the javascript to send the form data to the server. You can use $.ajax or $.post in jquery. Then you just need to set up a route and a controller on the web2py side to receive the post data and send the email based on said data.

Or you could just use a normal HTML form, and not use jquery at all...

thanks for the help!