PHP AJAX Email/Message Server
The AJAX Email/Message form is divided in two parts: the client side (handled by the browser) and the server side.
Client side
The HTML file and the JavaScript file
form_script.js
handle the client side.
Subscription form
The email subscription form is represented by the form
tag with
send_email_form
class. Edit its
action
attribute to point to your ajax server :
ajaxserver/serverfile.php
to save to a file,
ajaxserver/server.php
to send emails as message (Email message), and
ajaxserver/servermailchimp.php
to send emails to a mailchimp list (see server side section below for details).
Contact form
The contact form is represented by the form
tag with class
send_message_form
.
Edit its
action
attribute to point to your ajax server :
ajaxserver/serverfile.php
to save to a file,
ajaxserver/server.php
to send the message form as an email message to your email.
The JavaScript file "form_script.js" manages the sending of the data to the server and notify the user when it is done. There is no need to change its content.
Server side
You have to point you registration form and contact form in to an AJAX server as precised in the "Client side" section above.
The AJAX server used by this theme is PHP based. Three samples php-based AJAX server is provided under ajaxserver folder
:
- serverfile.php : Writes emails and messages in files called "email.txt" and "message.txt" respectively. You do not need to edit this file.
- server.php : Sends email and messages to your desired email addresses. Edit this file and replace all the
$recipient = "[email protected]";
by yours (there are two of it since message recipient and email subscription recipient could be different). You can also change the message content and subject by changing the$subject
and$email_content
variable.
IMPORTANT : Most of Web Hosting provider allow you to use only your domain based email (such as [email protected]) for this feature.
- servermailchimp.php : Uses mailchimp API to add user email to a mailchimp registration list.
IMPORTANT : You need a mailchimp API Key and a mailchimp List to make it working. To do so :
- First, create a Mailchimp account if you do not have one.
- Then create an API key here http://admin.mailchimp.com/account/api/
- Create also a Mailchimp mailing list here http://admin.mailchimp.com/lists/ , select the new list and click the "settings" menu - the Unique Id is at the bottom of that page.
-
Now, edit the "servermailchimp.php" file and change
$api = new MCAPI('YOUR_APIKEY_HERE')
to match to your api key. Change also$list_id = "YOUR_LISTID_HERE"
to your mailchimp list Unique Id. - Do not forget to change the action attribute of the email registration form within the HTML file to point to the mailchimp server :
These server handles messages and email subscription requests made by users.
Alternative server implementation
If you want to implement your own contact/emaillist server API (by using Node JS, Rails, .net ... server), it should send the following response, so that the default provided AJAX client can handle it: