UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / API / EmailSender Completed

API — UGTK

Email Sender

Summary

The Email Sender sends an email from the game by posting the fields to a PHP endpoint that does the actual SMTP work (PHPMailer ships in the module). Typical uses are a feedback form, a "send me my score" button, a contact form in an advergame.

Unity cannot speak SMTP from a build — least of all from WebGL — which is why the sending happens server-side and the game only fills in a form.

⚠️ Do not ship the SMTP password in the build

senderPassword is a serialized field: whatever you type in the prefab is written into the built game and can be read out of it by anyone. Keep the credentials on the server, inside the PHP script, and leave the field empty in Unity. Treat this component as "ask the server to send a mail", not as a mail client.


Content


Modules Dependencies


Setup

1. Add the PhpApiManager and PhpMailSender prefabs to the scene:

2. Configure the PhpApiManager with the base URL of your server:

Setup PHP manager

3. Configure the PhpMailSender — recipient, subject, body, and the optional attachment and signature:

Setup email sender

4. Upload the PHP side. Php/send_email/ contains the endpoint and the bundled PHPMailer: it has to be deployed on the server the manager points at. Nothing works until that is in place.


How To Use

Fill the fields from your UI, then send:

Send mail

mailSender.SetRecipientEmail(inputEmail.text);
mailSender.SetEmailSubject("Feedback from the game");
mailSender.SetEmailBody(inputMessage.text);
mailSender.SendEmail();

Every setter is a plain assignment, so it can be wired straight to an InputField's onValueChanged from the inspector:

Methods email sender

Method Sets
SetSenderEmail(string) the sender address
SetRecipientEmail(string) the recipient address
SetEmailSubject(string) the subject
SetEmailBody(string) the body
SetAttachmentPath(string) path of the file to attach
SetSignatureUrl(string) URL of the signature image
SendEmail() performs the send — also available from the component's context menu

Good to know:


Testing Scene

Open MailSenderScene in the module's Debug/ folder.

What to do, in order:

  1. Fill recipient, subject and body, then press SendEmail().
  2. Send to an address that does not exist.
  3. Attach a file with SetAttachmentPath() and send again.
  4. Send with an empty recipient.

Step 2 is worth understanding: the server accepts the message and the failure arrives later, by bounce, so a "sent" result does not mean "delivered". Do not build a confirmation screen that claims otherwise.

Then do the test everybody skips: turn the network off and repeat. A request that never answers is the normal condition on mobile, and it is where a game most often ends up stuck on a spinner with no way back.

The recording is the Mail Data block taking its four values: the account the mail goes out from, its password, who receives it and the subject. They arrive empty, because they are yours.

The demo scene stops there deliberately and so does this page. Simple Mail and Php Mail in the scene send a real message the moment you press them - there is no dry run - so fill the fields with an account you own before you touch either.

On that password field. It is a serialised value: whatever you type sits in plain text inside the prefab, and travels with it into source control and into any build. This package shipped with a working Gmail app password in exactly this field until it was found and removed. Use an app password rather than the account's own, keep it out of prefabs that get committed, and prefer setting it at runtime from somewhere the repository never sees.


Technical Info

Path Content
Scripts/Runtime/Mn_PhpEmailSender.cs Mn_PhpMailSender: the fields, the setters, SendEmail and the form built for the endpoint
Scripts/Editor/Mn_PhpMailSender_Editor.cs Custom inspector
Php/send_email/ The PHP endpoint and the bundled PHPMailer, to deploy on the server
Prefabs/PhpMailSender.prefab The ready-made component
Debug/MailSenderScene.unity Test scene

© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 4 modules in total.