Sending an Email from Construct2

3

Attached Files

The following files have been attached to this tutorial:

.capx

Stats

7,309 visits, 11,091 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 2 Dec, 2015. Last updated 30 Mar, 2019

Main aim of this Tutorial

This Tutorial will show you how to send a simple Email message from C2 or C3

Step 1

You will need your own Web host.

You will need to be able to upload FTP files up to your web host.

You will need an installed copy of Construct2 or Construct3

Step 2

Download the capx that I have provided, and open it in C2 or C3

Step 3

In The' Layout Tab' I have Inserted 6 'Objects'

1) Ajax Object.

2) A Button Object.

3) Three Text Box Objects.

4) A Text Object.

The Ajax Object communicates with the PHP Script.

The Button Object is for confirming to send your email.

The 3 Textbox Objects are for gathering your details.

The Text Object is for displaying a text message of confirmation.

Explanation of capx.

You will see I have set up 3 Global Variables.

1) email_to ......This will be the recipients address.

3) subject..........This will be your subject.

2) message.......This will be your message.

There are only 3 Events as follows.

1) System-Every Tick --->

a) Sets the input from the Subject Text Box to the Global variable 'subject'

b) Sets the input from the Message Text Box to the Global variable 'message'

c) Sets the input from the Email_address to the Global variable 'email_to'

2) Button-On Clicked --->

a) This sends the information from the' global varables ' to a 'PHP Script'

which is based on your Web Host.

It is important that you change the name of the URL 'Web address' to your own Web Hosting address, as this is where the information will be sent to.

The c2mail.php, on the end will be the 'PHP Script file' that we will write later.

There is a Tag at the end called 'email' as an identifier.

3) Ajax On "email" completed ---> "email" being our tag.

This sets the Text in the Text Object to the information requested from the 'PHP Script', with the expression AJAX.LastData

Step 4

Writing our 'PHP Script' file

We can now write our 'PHP Script' file.

1) Open up notepad on your pc and copy this 'PHP Script' file above

2) Save the file as c2mail.php

3) Upload the file to your Web Host, via FTP.

Explanation of PHP Script

Line 1, Open up the PHP code command

Line 2, Set up a String (variable) called $to, to put the information in with the 'POST'method, from our Email_to Global variable from Construct2.

Line 3, Set up a String (variable) called $subject, to put the information in with the 'POST'method, from our subject Global variable from Construct2.

Line 4, Set up a String (variable) called $message, to put the information in with the 'POST' method, from our message Global variable from Construct2.

Line 5, This can be set up as above , if you want information on who the email is from. But for this example, I am going to keep it as simple as possible.

Line 6, This is the PHP Mail command with all your $ variables in.

Line, 8 & 9 This is the information that we are going to use for our Text Object in Construct2.

Line 10, Close the Script.

Step 5

Export the capx to your web host as a html5 project.

Try it !!

Ok Check list

1) You have downloaded the Capx.

2) You have changed the URL in Ajax -- Send, to your own URL.

3) You have written the PHP Script file, and put it on your Web Host Web space.

4) You have exported your capx to your webhost (site)

Ok you should be ready to go.

It is advisable just to send an email to yourself at first, and remember if you do not change $headers in the PHP Script, the email sent will be from webmasterhhg@example.com

Note: It can take up to 15 minutes to receive the email, depending on your webhost

If there are any problems, be sure to check that your own URL is correct, and that the email has not gone into your Junk mail.

Cheers

Sizcoz

.CAPX
  • 5 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • I have 2 games using this technique and it doesn't appear to be working anymore. I haven't yet found the reason why it doesn't work. Any suggestion for alternatives would be greatly appreciated!

  • The entirety of Apple's phones accompany pre-introduced email applications. This application doesn't approach the further developed highlights you find in the Yahoo Mail application, (for example, overseeing envelopes, your record data, and subjects). You can include more than one record Yahoo Mail IT and send an email from for.

    This alterna

    1. tive is accessible for the new form of the OS.
    2. Opens the application iOS settings.
    3. Tap Accounts and Passwords.
    4. Add the invalid record.
    5. Press on Yahoo.
    6. Enter your Yahoo email address and secret key, at that point tap Sign in.
    7. Optionally incapacitated synchronization parts of Yahoo Mail.
    8. Save the subtleties t

    o get to your email.

    Source - https://hosting-reviews.co.uk/yahoo/yahoo-mail-login-sign-in-error-tutorial/

  • I just get an error message warning me that it's trying to load an unsafe program. when I override it, it changes my 'https' to 'not secure' and doesn't send the email. I think this might be too outdated.