I have a simple page with 3 textbox and a button like this.
<input type="text" ng-model="name" required >
<input type="text" ng-model="city" required >
<input type="text" ng-model="country" required >
<button class="button button-block button-royal ExploreBtn" ng-click="sendMail();">
Send mail
</button>
Help me , How to send mail with value in first text-field as subject and other two as body in angular js/ionic.
So, basically the comments to your question are correct - you can't do this purely in JavaScript, you need to use a backend service for it.
Now, what you would do in your sendMail
function is call the service by using Angulars' $http
service. You can learn more about $http service from the official documentation.
The call would, for example look like this:
$http({
method: 'POST',
url: 'http://your.server.com/sendmail.php',
data: { mailTo: '[email protected]', msg: 'hello!' }
}).then(function successCallback(response) {
alert("msg sent!");
}, function errorCallback(response) {
alert("error with sending a msg");
});
Here you have two important parts:
url
- where is your service (which will finally send the email) locateddata
- what are you sending to this service endpointIn my example I've put the service url to be sendmail.php
which, in end, would be written in PHP. I have to stress out that your backend service can be written in any server-side language you're familiar with (if you'll research this topic further make sure you read about the RESTful services).
For the sake of this example, the PHP script (unsecured and just for reference) which uses the mail function to send an email would look something like this:
<?php
$to = $_POST["emailTo"];
$msg = $_POST["msg"];
mail($to, "Some test subject", $msg);
?>
Hope this helps clear the confusion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With