Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by pretender · Dec 12, 2011 at 01:33 PM · phpemailsend

send email from unity?

Hi everybody!

I want to be able to send email from unity. I have the php script that i use to send emails from web page,i was wondering is it possible to use it from unity.

if i have this code (very simple): how could i send email from unity?

 <?php
 // Pick up the form data and assign it to variables
 $object = $_POST['object'];
 $text= $_POST['text'];
 $email = $_POST['email'];
 
 
 $to='message@domain.com';
 $subject="$object";
 $message="text: $text";
 $headers = "From: $email";
 
 // Send the mail using PHPs mail() function
 mail($to, $subject, $message, $headers);
 ?>

thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by jheiling · Dec 12, 2011 at 02:43 PM

If you want to call a PHP script on the server use WWW

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Dec 23, 2011 at 01:29 PM 0
Share

Yep, that would be the best solution ;)

avatar image
4

Answer by Bunny83 · Dec 23, 2011 at 01:29 PM

Unity of course don't have a build in email server. Allowing your users to send emails is not such a good idea. The "usual" way to send an email is to send it via your email provider like described here. However, it's possible to directly send an email to the target email-providers smtp server. But in this case your computer is the sending email server. A lot email providers block emails from unknown sources to prevent spam(*). If you use a php script like you've mentioned, it's executed on your web server (like all php scripts) and this one will act as mail server and send the mail directly. If your web hoster is a trusted server it's always the best way. But you should implement some kind of spam prevention so users can't send tons of emails through your server, or your server will end up on a global black list.

(*) If an email server receives an email from an unknown host it usually answers with a "bad request" error to test if you are a real server (that tries to resend after some time). Most email server don't allow faked email source adresses (if they can tell). For example if you directly send an email to gmx and you insert your own gmx address as source address, the gmx server will refuse the mail since it know for certain that your IP is not a gmx server.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

Answer by by0log1c · Dec 23, 2011 at 01:43 PM

I'm just passing by and see some answers were proposed, but in case you want to know how to actually use the script you have. You'd need to upload that PHP to a web server, follow Bunny83's advices.

Then, within Unity, you need to send a Post request to the PHP, using WWWForm and WWW:

 var url:String = "www.myserver.com/myscript.php";
 var form:WWWForm = new WWWForm();
 
 form.AddField("object","MY OBJECT");
 form.AddField("text","MY TEXT");
 form.AddField("email","MY EMAIL");
 
 var www:WWW = new WWW(url,form);
 yield www;

remember that when dealing with php, user inputs and such, security/sanity checks is a must to prevent malicious user's activity.

Hope that helps.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nabil_fx · Nov 06, 2014 at 02:31 PM 0
Share

I made a game, with unity, how could i make a control to know when somebody really win the game automatic send me a code or something like that. To prevent fraud.

This gonna happened when the player load level finish, them the security message or email i received. Any sugestion?

avatar image
-1

Answer by ks13 · Dec 12, 2011 at 01:52 PM

ExternalCall?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Dec 23, 2011 at 01:14 PM 1
Share

No, ExternalCall only works in the webplayer and it only executes JScript code inside the webpage. You can't execute PHP code on the client side.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Add a byte[] as attachment in a mail 1 Answer

A simple e-mail script using php/C# 0 Answers

Unity 3 - Sending Email with C# 6 Answers

How do I send an email on IOS using Application.OpenURL with more than one line of body text? 4 Answers

Send an email from unity to email adress? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges