Hi guys, I am new in game development. I am attempting to send an email through input fields but I have been receiving NullReferenceException when I click the Submit button.
Here are my codes:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
[RequireComponent(typeof(InputField))]
public class FeedbackForm : MonoBehaviour {
InputField emailInputField;
InputField subjectInputField;
InputField messageInputField;
void Start()
{
emailInputField = GetComponent();
subjectInputField = GetComponent();
messageInputField = GetComponent();
}
void SendTheMail(string text)
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(“darrenleejingyu@gmail.com”);
mail.To.Add(“askflytech@gmail.com”);
mail.Subject = “Test Mail”;
mail.Body = text;
SmtpClient smtpServer = new SmtpClient(“smtp.gmail.com”);
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential(“askflytech@gmail.com”, “flytechadmin2017”) as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpServer.Send(mail);
Debug.Log(“success”);
}
public void OnBackToMainMenuClick()
{
SceneManager.LoadScene(“Mainpage”);
}
void OnSubmitButtonClick()
{
SendTheMail(messageInputField.text);
}
}
Can you guys help me to point out where is the mistake and how to fix that?
Your help is greatly appreciated. Thank you