Ok.
I have changed the example to do an email using php.
Here is the new Hype project. Export it and place on Server.
messagesent.hypetemplate.zip (91.8 KB)
The code in the Project:
hypeDocument.getElementById('resultBox').innerHTML = "";
var name = hypeDocument.getElementById('name').value;
var email = hypeDocument.getElementById('email').value;
var phone = hypeDocument.getElementById('phone').value;
var message = hypeDocument.getElementById('message').value;
var obj = new Object();
var PostName = name;
var PostemailAddr =email;
var Postphone = phone;
var Postmessage = message;
phpEmailer(PostName, PostemailAddr,Postphone,Postmessage);
function phpEmailer(PostName, PostemailAddr,Postphone,Postmessage){
$.post("./email2.php", { name: PostName, email: PostemailAddr,phone: Postphone,message: Postmessage} )
.done(function() {
hypeDocument.getElementById('resultBox').innerHTML = "success" ;
})
.fail(function() {
//do anything on failure ...
hypeDocument.getElementById('resultBox').innerHTML = "failure";
});
}
Along side the html file on the server, place this php file. You will need to change the to email address to the one you want to receive the data to.
( original php code: http://stackoverflow.com/questions/20927980/using-html-and-php-to-send-form-data-to-an-email )
The php script also sends an email confirmation to the user.
email2.php.zip (887 Bytes)
The code in the file:
<?php
$email = $_POST["email"];
$to = "me@me.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$name = $_POST["name"];
$phone = $_POST["phone"];
$message = $_POST["message"];
$body = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email\n
Name: $name\n
Phone:$phone\n
Message: $message
";
mail($to,$subject,$body,$headers);
#send confirmation email to users email address
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you@youremailaddress.com\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($user,$usersubject,$usermessage,$userheaders);
?>
Note This is all new to me also, so any validation on the posting to PHP you should look up and do yourself as it is not really in the scope of this site on how to write and validate php. Also I do not now enough about php, server safety to approach it nor can I confirm if any of the PHP and approach above is safe to use in the real world. I assume it is but you would need to check this your self…