Is it possible to send an email in the background?
I want to take something that a user typed in a textarea and when they hit "Go" it will email it to a predefined email address.
Does anyone know how to go about doing this?
3 Answers
-
You can try this:
In Titanium mailSender.js
//Variables var emailTo = "mymail@mail.com"; var emailSubject= "my subject"; var emailMessage = " My message "; var xhrURL = "http://myserver.com/email.php"; var xhr_object = Ti.Network.createHTTPClient(); xhr_object.open("POST", xhrURL, true); xhr_object.setRequestHeader( "Content-type" , "application/x-www-form-urlencoded" ); xhr_object.setRequestHeader( "Connection" , "close" ); //Post Data var postData = ({ to : emailTo , message : emailMessage, subject: emailSubject }); xhr_object.send(postData); xhr_object.onload = function(){ Titanium.API.info(this.responseText) //Log response } xhr_object.onerror = function(){ alert("Error!") }
then in the server email.php
<? //get the vars from the post array $to = $_POST['to'] ; $subject = $_POST['subject'] ; $message = $_POST['message'] ; mail($to,$subject,$message); //For log variables var_dump($_REQUEST); print "Mail sent"; ?>
-
Would this work?
var emailDialog = Titanium.UI.createEmailDialog(); emailDialog.setSubject('Subject Name!'); emailDialog.toRecipients = ['youremail@gmail.com']; emailDialog.setMessageBody('Hey! You should check out the App \n\nThe App is available for FREE on both the Apple App Store and the Android Marketplace!'); emailDialog.SENT;
I don't receive an email (i'm assuming because I'm still testing on my computer because I did the stand version of the code and still didn't receive an email)
-
Just send it to a Webservice like a PHP script like this:
var xhr = Titanium.Network.createHTTPClient(); xhr.open("POST", 'http://YOUR.WEBSERVER/email.php' ); xhr.send({email:EmailVar, content:AnotherVar});