Sending mail (from Unity3D)


You are looking for a solution to send an email with Unity3D but, it’s not simple ?

If you’re looking on Internet, you’ll see lot’s of c# implementations but not workig on all platforms. (Android)

So my solution is very simple if you have a website. You just need to put this PHP5 file online :


$From  = "\n";
$From .= "MIME-version: 1.0\n";
$From .= "Content-type: text/html; charset= iso-8859-1\n";

$newSubject = nl2br(stripslashes($_GET["subject"]));
$newBody = nl2br(stripslashes($_GET["body"]));

if (mail($_GET["to"], utf8_decode($newSubject), utf8_decode($newBody), $From)) 
  echo("<p>Message successfully sent!</p>");
  echo("<p>Message delivery failed ...</p>");


In Unity, add this method in a MonoBehaviour c# script :

public IEnumerator SendMail(string to, string subject, string message)
string url = "" + to + "&subject=" + WWW.EscapeURL(subject) + "&body=" + WWW.EscapeURL(message);
WWW request = new WWW(url);
yield return request;

To send an email, the call is :

StartCoroutine(SendMail("", "The Subject", "My Message"));

Don’t forget to change the sender in the php file

This work on every plateform.

With this script, you can send mail from everyone you want, be carreful.



Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *