Sending system information feedback to designated email address

This is my code:

var OS : String;
var coreType : String;
var sysMemory : String;
var graMemory : String;
var graDeviceName : String;
var graDeviceVendor : String;
var ShaderLevel : String;
var SupportShadows : String;
var SupportRenderTexture : String;
var SupportImageEffects : String;

function Start () {
	OS = SystemInfo.operatingSystem;
	coreType = SystemInfo.processorType;
	sysMemory = SystemInfo.systemMemorySize.ToString();
	graMemory = SystemInfo.graphicsMemorySize.ToString();
	graDeviceName = SystemInfo.graphicsDeviceName;
	graDeviceVendor = SystemInfo.graphicsDeviceVendor;
	ShaderLevel = SystemInfo.graphicsShaderLevel.ToString();
	SupportShadows = SystemInfo.supportsShadows.ToString();
	SupportRenderTexture = SystemInfo.supportsRenderTextures.ToString();
	SupportImageEffects = SystemInfo.supportsImageEffects.ToString();
}

I would like to use a PHP function (or any function that may work) to send an email to a predefined email address, with the message containing all of the defined strings. I would like to use this as a “first run only” utility, to help me gather information for usage statistics. I am planning on launching an indev testing session within the month, and the gathered information would be useful for statistics…

I know I don’t have to define variables. I did that for aesthetic purposes…

I know there’s a question in there somewhere, but I’m having difficulty finding it.

I will though suggest that it would be easier for you to pour over your metrics if you simply populate a database with the PHP, instead of using it to send you a text document.

I don’t have a large enough population to have an entire database for it. It is an extremely closed indev test, less than ten.

Sorry for making the question so difficult to find. I guess a way to ask it that may make other things useful as well is can we use PHP in Unity and, if so, how do we implement it?

All usefulness aside, it would be an interesting toy…

create a www function that sends the info to php and let php parse the info and send the email.
if you only want to send it once, write a boolean to playerprefs or xml and set it to false, check for the boolean when the function gets called. if the boolean exists, don’t execute the function anymore.

PHPMailer will come in handy for actually sending the email…
You can use it to send the email over gmail’s SMTP as well which will greatly reduce the chances of your email being filtered out as junk.

Here’s a link very basically detailing how to do this

As appels said, all you need to do is use Unity to create a WWWForm populated with the game data and submit it to your PHP script.

Is there a Csharp alternative?

Dude, that’s sick. You rock.

Vimalakirti, you have 666 posts, good sir…

Almost hate to ruin it!

oops…

Oh if you plan on using this I should not that the link I sent details how to do it with the older version of PHPMailer. I think it’s actually easier now if you can believe it. A quick google of “gmail phpmailer” will do the trick!

That will help! I did get it up and running but attaching the screenshot is another trick. Still working on it!

thanks

Can’t you send an e-mail through gmail’s smtp using .NET’s Mail namespace, and circumvent using PHP at all?

I don’t know. Can I? How?

I’ve never tried it, but something like this maybe:

I translated them. Here’s the ScreenShot.cs:

using UnityEngine;
using System.Collections;

public class ScreenShot : MonoBehaviour 
{
	public string screenShotURL= "http://yoursite.com/image.php";

	void OnGUI() 
	{
		if(GUI.Button(new Rect(Screen.width * 0.5f, Screen.height - 80f, 50f, 30f),"Save"))
		{
			print("now really going to Upload");
			UploadNow();
		}
	}
	
	void UploadNow()
	{
		StartCoroutine (UploadPNG(OnShotSaved));
	}
	
	public delegate void ResultVerifier (bool result);
	
	
	IEnumerator UploadPNG(ResultVerifier handler)
	{
			// Wait for the frame to finish drawing:
        yield return new WaitForEndOfFrame();
		
	    	// Create a texture the size of the screen, RGB24 format
	    float width = Screen.width;
	    float height = Screen.height;
	    Texture2D tex = new Texture2D( (int) (width), (int) (height), TextureFormat.RGB24, false );
		
	    	// Read screen contents into the texture
	    tex.ReadPixels( new Rect(0f, 0f, width, height), 0, 0 );
	    tex.Apply();
	
	    	// Encode texture into PNG
	    byte[] bytes = tex.EncodeToPNG();
	    Destroy( tex );
	
	    	// Create a Web Form
	    WWWForm form = new WWWForm();
	    form.AddField("frameCount", Time.frameCount.ToString());
	    form.AddBinaryData("image", bytes, "screenShot.png", "image/png");
	
	    	// Upload to a cgi script    
	    WWW w = new WWW(screenShotURL, form);
		
			// Wait while it's uploading, give up after 10 seconds:
		float stop = Time.timeSinceLevelLoad + 10.0f;
		while (!w.isDone  stop > Time.timeSinceLevelLoad)
		{
			yield return new WaitForSeconds (1);
		}
		
		bool result = true;
		
	    if (w.error != null)
	    {
			result = false;
	        print(w.error);    
	    }
	    else
	    {
	        print("Finished Uploading Screenshot");    
	    }
		
		handler( result );
	}
	
	void OnShotSaved(bool result)
	{
		print("OnShotSaved is:"+result);
	}
}

And here is the script to read the image and apply it as a texture, ApplyShot.cs:

using UnityEngine;
using System.Collections;

public class ApplyShot : MonoBehaviour 
{
	Material mat;
	public string url = "http://yoursite.com/images/screenShot.png";

	void Start() 
	{
			// Find the material to apply the texture to:
		mat = renderer.material;
			// Get and apply the texture:
		GetTexture();
	}
	
	public delegate void ResultHandler (Texture2D result);
	
	void GetTexture()
	{
		StartCoroutine (LoadTexture(OnTextureLoaded));
	}
	
	public IEnumerator LoadTexture(ResultHandler handler)
	{
		Texture2D newTex = null;
		
			// Get url:
		WWW www = new WWW(url);
		
			// Wait while it's downloading, give up after 10 seconds:
		float stop = Time.timeSinceLevelLoad + 10.0f;
		while(!www.isDone  stop > Time.timeSinceLevelLoad)
		{
			yield return new WaitForSeconds (1);
		}
			
	    if (www.error != null) 
		{
	        Debug.Log ("There was an error getting the texture: " + www.error);
	    }
		else 
		{
			newTex = www.texture;
			mat.mainTexture = www.texture;
		}
		
		handler (newTex);
	}
	
	void OnTextureLoaded(Texture2D newTex)
	{
			// and apply the material, or whatever:
		mat.mainTexture = newTex;
	}
}

That looks really really great. Unfortunately, when I put in the code:

using UnityEngine;
using System.Collections;
using System.Net.Mail;
using System.Net;

I get the error:
Assets/Scripts/PHP/Email01.cs(3,18): error CS0234: The type or namespace name Mail' does not exist in the namespace System.Net’. Are you missing an assembly reference?

I don’t know how to add assemblies and am not sure if Unity will let me. Any ideas?

I doubt you’ll get the C# only version working as Unity doesn’t seem to work with the System.Net classes. Not to mention the fact that your application would have to contain your gmail username and password in the source code… not good.

Oh, didn’t even think of that, with how easy it is to decompile Unity. That would definitely be bad. I’d still to the WWW/PHP.