I am using the following code to allow my AngularJS app users to send emails using their favorite mail client, but when I click on the Send button nothing happens. Can someone please check my code and tell me what exactly I am missing here? Thanks
<button type="button" ng-click="sendEmail(message.Email, message.subject, message.body)" >Send</button>
Controller code:
$scope.sendEmail = function(email, subject, body){
var link = "mailto:"+ email
+ "&subject=New email " + escape(subject);
+ "&body=" + escape(body);
window.location.href = link;
};
2 things I can think may be wrong here.
First off, Spaces aren't valid characters in the subject. You may have to replace this with a %20
.
Second, you will need to change the &
before the subject to a ?
. Otherwise it will try to send an email to the address including all of the subject and body parameters...
Can you try this instead:
$scope.sendEmail = function(email, subject, body) {
var link = "mailto:"+ email
+ "?subject=New%20email " + escape(subject)
+ "&body=" + escape(body);
window.location.href = link;
};
You can view some more info here: http://en.wikipedia.org/wiki/Mailto
If someone is still using the upvoted answer, remember to remove the semi-colon on the subject escape.
this:
+ escape(subject);
should be:
+ escape(subject)
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