How to send email when a form gets submitted [Django-rest-framework]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have made an api for submitting a contact form in my application.
Whenever the form gets submitted i want it to send that details to myself through email.
Here is my code what i am using:



models.py



class Contact(models.Model):
name = models.CharField(max_length=255)
email = models.EmailField(max_length=254)
phone = models.CharField(max_length=20)
message = models.TextField()

def __str__(self):
return self.name

class Meta:
db_table = 'contact'


views.py



from rest_framework.generics import (
CreateAPIView,
)
from .serializers import (
ContactCreateSerializer
)
class ContactCreateApiView(CreateAPIView):
queryset = Contact.objects.all()
serializer_class = ContactCreateSerializer


serializers.py



class ContactCreateSerializer(ModelSerializer):
class Meta:
model = Contact
fields = [
'name',
'email',
'phone',
'message',
]

def send_email(self):
name = self.cleaned_data.get('name')
from_email = self.cleaned_data.get('email')
phone = self.cleaned_data.get('phone')
subject = 'Contact Form Info from App'
message = self.cleaned_data.get('message')
to_email = settings.EMAIL_HOST_USER

context = {
'name': name,
'email': from_email,
'phone': phone,
'message': message,
}
plaintext = get_template('emails/contact_form_email.txt')
htmly = get_template('emails/contact_form_email.html')
text_content = plaintext.render(context)
html_content = htmly.render(context)

message = EmailMultiAlternatives(
subject=subject,
body=text_content,
from_email=from_email,
to=[to_email],
cc=,
bcc=
)
message.attach_alternative(html_content, "text/html")
message.send()

def save(self, commit=True):
instance = super().save(commit)
self.send_email() # there you send the email when then model is saved in db
return instance


I tried this but it gives me error



save() takes 1 positional argument but 2 were given


What should i do?










share|improve this question

























  • Welcome to SO. While we're all happy to help with real problems, we're not here to to your job for free, and you are expected to do some research by yourself first. Sending mails from Django is quite extensively documented, with lot of example, so there's really no reason to ask such a question here. If you actually tried something and had issues, please edit your post to explain what you did and how exactly it didn't work (including error messages and the full traceback).

    – bruno desthuilliers
    Jan 4 at 10:11











  • @brunodesthuilliers See i have updated the post

    – Aadil Shaikh
    Jan 4 at 10:56











  • You forgot to include the full traceback - the error message by itself is not enough to know where the problem comes from. But from your code it seems like you've copy-pasted some code that was written for a ModelForm, while your cass is a drf ModelSerializer - and if you look are DRF source code, ModelSerializer.save doesn't take any positional argument indeed. Code snippets are useful examples, but you stil have to understand them and the context in which they are used, just copy-pasting some code out of context is only going to get you such problems.

    – bruno desthuilliers
    Jan 4 at 14:22


















0















I have made an api for submitting a contact form in my application.
Whenever the form gets submitted i want it to send that details to myself through email.
Here is my code what i am using:



models.py



class Contact(models.Model):
name = models.CharField(max_length=255)
email = models.EmailField(max_length=254)
phone = models.CharField(max_length=20)
message = models.TextField()

def __str__(self):
return self.name

class Meta:
db_table = 'contact'


views.py



from rest_framework.generics import (
CreateAPIView,
)
from .serializers import (
ContactCreateSerializer
)
class ContactCreateApiView(CreateAPIView):
queryset = Contact.objects.all()
serializer_class = ContactCreateSerializer


serializers.py



class ContactCreateSerializer(ModelSerializer):
class Meta:
model = Contact
fields = [
'name',
'email',
'phone',
'message',
]

def send_email(self):
name = self.cleaned_data.get('name')
from_email = self.cleaned_data.get('email')
phone = self.cleaned_data.get('phone')
subject = 'Contact Form Info from App'
message = self.cleaned_data.get('message')
to_email = settings.EMAIL_HOST_USER

context = {
'name': name,
'email': from_email,
'phone': phone,
'message': message,
}
plaintext = get_template('emails/contact_form_email.txt')
htmly = get_template('emails/contact_form_email.html')
text_content = plaintext.render(context)
html_content = htmly.render(context)

message = EmailMultiAlternatives(
subject=subject,
body=text_content,
from_email=from_email,
to=[to_email],
cc=,
bcc=
)
message.attach_alternative(html_content, "text/html")
message.send()

def save(self, commit=True):
instance = super().save(commit)
self.send_email() # there you send the email when then model is saved in db
return instance


I tried this but it gives me error



save() takes 1 positional argument but 2 were given


What should i do?










share|improve this question

























  • Welcome to SO. While we're all happy to help with real problems, we're not here to to your job for free, and you are expected to do some research by yourself first. Sending mails from Django is quite extensively documented, with lot of example, so there's really no reason to ask such a question here. If you actually tried something and had issues, please edit your post to explain what you did and how exactly it didn't work (including error messages and the full traceback).

    – bruno desthuilliers
    Jan 4 at 10:11











  • @brunodesthuilliers See i have updated the post

    – Aadil Shaikh
    Jan 4 at 10:56











  • You forgot to include the full traceback - the error message by itself is not enough to know where the problem comes from. But from your code it seems like you've copy-pasted some code that was written for a ModelForm, while your cass is a drf ModelSerializer - and if you look are DRF source code, ModelSerializer.save doesn't take any positional argument indeed. Code snippets are useful examples, but you stil have to understand them and the context in which they are used, just copy-pasting some code out of context is only going to get you such problems.

    – bruno desthuilliers
    Jan 4 at 14:22














0












0








0








I have made an api for submitting a contact form in my application.
Whenever the form gets submitted i want it to send that details to myself through email.
Here is my code what i am using:



models.py



class Contact(models.Model):
name = models.CharField(max_length=255)
email = models.EmailField(max_length=254)
phone = models.CharField(max_length=20)
message = models.TextField()

def __str__(self):
return self.name

class Meta:
db_table = 'contact'


views.py



from rest_framework.generics import (
CreateAPIView,
)
from .serializers import (
ContactCreateSerializer
)
class ContactCreateApiView(CreateAPIView):
queryset = Contact.objects.all()
serializer_class = ContactCreateSerializer


serializers.py



class ContactCreateSerializer(ModelSerializer):
class Meta:
model = Contact
fields = [
'name',
'email',
'phone',
'message',
]

def send_email(self):
name = self.cleaned_data.get('name')
from_email = self.cleaned_data.get('email')
phone = self.cleaned_data.get('phone')
subject = 'Contact Form Info from App'
message = self.cleaned_data.get('message')
to_email = settings.EMAIL_HOST_USER

context = {
'name': name,
'email': from_email,
'phone': phone,
'message': message,
}
plaintext = get_template('emails/contact_form_email.txt')
htmly = get_template('emails/contact_form_email.html')
text_content = plaintext.render(context)
html_content = htmly.render(context)

message = EmailMultiAlternatives(
subject=subject,
body=text_content,
from_email=from_email,
to=[to_email],
cc=,
bcc=
)
message.attach_alternative(html_content, "text/html")
message.send()

def save(self, commit=True):
instance = super().save(commit)
self.send_email() # there you send the email when then model is saved in db
return instance


I tried this but it gives me error



save() takes 1 positional argument but 2 were given


What should i do?










share|improve this question
















I have made an api for submitting a contact form in my application.
Whenever the form gets submitted i want it to send that details to myself through email.
Here is my code what i am using:



models.py



class Contact(models.Model):
name = models.CharField(max_length=255)
email = models.EmailField(max_length=254)
phone = models.CharField(max_length=20)
message = models.TextField()

def __str__(self):
return self.name

class Meta:
db_table = 'contact'


views.py



from rest_framework.generics import (
CreateAPIView,
)
from .serializers import (
ContactCreateSerializer
)
class ContactCreateApiView(CreateAPIView):
queryset = Contact.objects.all()
serializer_class = ContactCreateSerializer


serializers.py



class ContactCreateSerializer(ModelSerializer):
class Meta:
model = Contact
fields = [
'name',
'email',
'phone',
'message',
]

def send_email(self):
name = self.cleaned_data.get('name')
from_email = self.cleaned_data.get('email')
phone = self.cleaned_data.get('phone')
subject = 'Contact Form Info from App'
message = self.cleaned_data.get('message')
to_email = settings.EMAIL_HOST_USER

context = {
'name': name,
'email': from_email,
'phone': phone,
'message': message,
}
plaintext = get_template('emails/contact_form_email.txt')
htmly = get_template('emails/contact_form_email.html')
text_content = plaintext.render(context)
html_content = htmly.render(context)

message = EmailMultiAlternatives(
subject=subject,
body=text_content,
from_email=from_email,
to=[to_email],
cc=,
bcc=
)
message.attach_alternative(html_content, "text/html")
message.send()

def save(self, commit=True):
instance = super().save(commit)
self.send_email() # there you send the email when then model is saved in db
return instance


I tried this but it gives me error



save() takes 1 positional argument but 2 were given


What should i do?







django django-rest-framework






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 10:56







Aadil Shaikh

















asked Jan 4 at 9:14









Aadil ShaikhAadil Shaikh

17513




17513













  • Welcome to SO. While we're all happy to help with real problems, we're not here to to your job for free, and you are expected to do some research by yourself first. Sending mails from Django is quite extensively documented, with lot of example, so there's really no reason to ask such a question here. If you actually tried something and had issues, please edit your post to explain what you did and how exactly it didn't work (including error messages and the full traceback).

    – bruno desthuilliers
    Jan 4 at 10:11











  • @brunodesthuilliers See i have updated the post

    – Aadil Shaikh
    Jan 4 at 10:56











  • You forgot to include the full traceback - the error message by itself is not enough to know where the problem comes from. But from your code it seems like you've copy-pasted some code that was written for a ModelForm, while your cass is a drf ModelSerializer - and if you look are DRF source code, ModelSerializer.save doesn't take any positional argument indeed. Code snippets are useful examples, but you stil have to understand them and the context in which they are used, just copy-pasting some code out of context is only going to get you such problems.

    – bruno desthuilliers
    Jan 4 at 14:22



















  • Welcome to SO. While we're all happy to help with real problems, we're not here to to your job for free, and you are expected to do some research by yourself first. Sending mails from Django is quite extensively documented, with lot of example, so there's really no reason to ask such a question here. If you actually tried something and had issues, please edit your post to explain what you did and how exactly it didn't work (including error messages and the full traceback).

    – bruno desthuilliers
    Jan 4 at 10:11











  • @brunodesthuilliers See i have updated the post

    – Aadil Shaikh
    Jan 4 at 10:56











  • You forgot to include the full traceback - the error message by itself is not enough to know where the problem comes from. But from your code it seems like you've copy-pasted some code that was written for a ModelForm, while your cass is a drf ModelSerializer - and if you look are DRF source code, ModelSerializer.save doesn't take any positional argument indeed. Code snippets are useful examples, but you stil have to understand them and the context in which they are used, just copy-pasting some code out of context is only going to get you such problems.

    – bruno desthuilliers
    Jan 4 at 14:22

















Welcome to SO. While we're all happy to help with real problems, we're not here to to your job for free, and you are expected to do some research by yourself first. Sending mails from Django is quite extensively documented, with lot of example, so there's really no reason to ask such a question here. If you actually tried something and had issues, please edit your post to explain what you did and how exactly it didn't work (including error messages and the full traceback).

– bruno desthuilliers
Jan 4 at 10:11





Welcome to SO. While we're all happy to help with real problems, we're not here to to your job for free, and you are expected to do some research by yourself first. Sending mails from Django is quite extensively documented, with lot of example, so there's really no reason to ask such a question here. If you actually tried something and had issues, please edit your post to explain what you did and how exactly it didn't work (including error messages and the full traceback).

– bruno desthuilliers
Jan 4 at 10:11













@brunodesthuilliers See i have updated the post

– Aadil Shaikh
Jan 4 at 10:56





@brunodesthuilliers See i have updated the post

– Aadil Shaikh
Jan 4 at 10:56













You forgot to include the full traceback - the error message by itself is not enough to know where the problem comes from. But from your code it seems like you've copy-pasted some code that was written for a ModelForm, while your cass is a drf ModelSerializer - and if you look are DRF source code, ModelSerializer.save doesn't take any positional argument indeed. Code snippets are useful examples, but you stil have to understand them and the context in which they are used, just copy-pasting some code out of context is only going to get you such problems.

– bruno desthuilliers
Jan 4 at 14:22





You forgot to include the full traceback - the error message by itself is not enough to know where the problem comes from. But from your code it seems like you've copy-pasted some code that was written for a ModelForm, while your cass is a drf ModelSerializer - and if you look are DRF source code, ModelSerializer.save doesn't take any positional argument indeed. Code snippets are useful examples, but you stil have to understand them and the context in which they are used, just copy-pasting some code out of context is only going to get you such problems.

– bruno desthuilliers
Jan 4 at 14:22












1 Answer
1






active

oldest

votes


















1














There are many ways to do that. One of them is to override the create method of the ModelSerializer:



from django.core.mail import send_mail


class ContactCreateSerializer(ModelSerializer):
class Meta:
model = ContactForm
fields = [
'name',
'email',
'phone',
'message',
]

def create(self, validate_data):
instance = super(ContactCreateSerializer, self).create(validate_data)
send_mail(
'Instance {} has been created'.format(instance.pk),
'Here is the message. DATA: {}'.format(validate_data),
'from@example.com',
['to@example.com'],
fail_silently=False,
)
return instance


For more details on sending email, please check this documentation.



FYI: Please change your Model Name from ContactForm to Contact. Because its a model, not a form. And to be honest. You don't need to store contact information. You can do it like this:



class ContactSerailizer(Serializer):
name = serializers.CharField()
email = serializers.EmailField()
# and so on

Class ContactView(APIView):
def post(self, request, *args, **kwargs):
serailizer = ContactSerailizer(request.data)
if serailizer.is_valid():
data = serailizer.validated_data
email = validated_data.get('email')
name = validated_data.get('name')
send_mail(
'Sent email from {}'.format(name),
'Here is the message. {}'.format(validate_data.get('message')),
email,
['to@example.com'],
fail_silently=False,
)
return Response({"success": "Sent"})
return Response({'success': "Failed"}, status=status.HTTP_400_BAD_REQUEST)





share|improve this answer


























  • the mail protocol is highly unreliable - the fact the mail was "sent" doesn't garantee it will actually reach it's destination - so saving contact forms data is always a good idea (if those are of any interest to you of course - but else why bother having a contact form ?)

    – bruno desthuilliers
    Jan 4 at 10:14











  • I agree with you. But having both emails and storing data is kind of redundant, isn't it?

    – ruddra
    Jan 4 at 10:28











  • @ruddra The Answer worked for me, thanks and i know that it would be redundant to have both email and stored data. I am doing that because in future i would need that data, instead of searching those mails i will directly go to my database and and export.

    – Aadil Shaikh
    Jan 4 at 11:40











  • @ruddra no it's not - the point is that there is absolutely NO garantee you will ever get the email, so storing the contact data ensure it won't get lost.

    – bruno desthuilliers
    Jan 4 at 14:09












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54035949%2fhow-to-send-email-when-a-form-gets-submitted-django-rest-framework%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














There are many ways to do that. One of them is to override the create method of the ModelSerializer:



from django.core.mail import send_mail


class ContactCreateSerializer(ModelSerializer):
class Meta:
model = ContactForm
fields = [
'name',
'email',
'phone',
'message',
]

def create(self, validate_data):
instance = super(ContactCreateSerializer, self).create(validate_data)
send_mail(
'Instance {} has been created'.format(instance.pk),
'Here is the message. DATA: {}'.format(validate_data),
'from@example.com',
['to@example.com'],
fail_silently=False,
)
return instance


For more details on sending email, please check this documentation.



FYI: Please change your Model Name from ContactForm to Contact. Because its a model, not a form. And to be honest. You don't need to store contact information. You can do it like this:



class ContactSerailizer(Serializer):
name = serializers.CharField()
email = serializers.EmailField()
# and so on

Class ContactView(APIView):
def post(self, request, *args, **kwargs):
serailizer = ContactSerailizer(request.data)
if serailizer.is_valid():
data = serailizer.validated_data
email = validated_data.get('email')
name = validated_data.get('name')
send_mail(
'Sent email from {}'.format(name),
'Here is the message. {}'.format(validate_data.get('message')),
email,
['to@example.com'],
fail_silently=False,
)
return Response({"success": "Sent"})
return Response({'success': "Failed"}, status=status.HTTP_400_BAD_REQUEST)





share|improve this answer


























  • the mail protocol is highly unreliable - the fact the mail was "sent" doesn't garantee it will actually reach it's destination - so saving contact forms data is always a good idea (if those are of any interest to you of course - but else why bother having a contact form ?)

    – bruno desthuilliers
    Jan 4 at 10:14











  • I agree with you. But having both emails and storing data is kind of redundant, isn't it?

    – ruddra
    Jan 4 at 10:28











  • @ruddra The Answer worked for me, thanks and i know that it would be redundant to have both email and stored data. I am doing that because in future i would need that data, instead of searching those mails i will directly go to my database and and export.

    – Aadil Shaikh
    Jan 4 at 11:40











  • @ruddra no it's not - the point is that there is absolutely NO garantee you will ever get the email, so storing the contact data ensure it won't get lost.

    – bruno desthuilliers
    Jan 4 at 14:09
















1














There are many ways to do that. One of them is to override the create method of the ModelSerializer:



from django.core.mail import send_mail


class ContactCreateSerializer(ModelSerializer):
class Meta:
model = ContactForm
fields = [
'name',
'email',
'phone',
'message',
]

def create(self, validate_data):
instance = super(ContactCreateSerializer, self).create(validate_data)
send_mail(
'Instance {} has been created'.format(instance.pk),
'Here is the message. DATA: {}'.format(validate_data),
'from@example.com',
['to@example.com'],
fail_silently=False,
)
return instance


For more details on sending email, please check this documentation.



FYI: Please change your Model Name from ContactForm to Contact. Because its a model, not a form. And to be honest. You don't need to store contact information. You can do it like this:



class ContactSerailizer(Serializer):
name = serializers.CharField()
email = serializers.EmailField()
# and so on

Class ContactView(APIView):
def post(self, request, *args, **kwargs):
serailizer = ContactSerailizer(request.data)
if serailizer.is_valid():
data = serailizer.validated_data
email = validated_data.get('email')
name = validated_data.get('name')
send_mail(
'Sent email from {}'.format(name),
'Here is the message. {}'.format(validate_data.get('message')),
email,
['to@example.com'],
fail_silently=False,
)
return Response({"success": "Sent"})
return Response({'success': "Failed"}, status=status.HTTP_400_BAD_REQUEST)





share|improve this answer


























  • the mail protocol is highly unreliable - the fact the mail was "sent" doesn't garantee it will actually reach it's destination - so saving contact forms data is always a good idea (if those are of any interest to you of course - but else why bother having a contact form ?)

    – bruno desthuilliers
    Jan 4 at 10:14











  • I agree with you. But having both emails and storing data is kind of redundant, isn't it?

    – ruddra
    Jan 4 at 10:28











  • @ruddra The Answer worked for me, thanks and i know that it would be redundant to have both email and stored data. I am doing that because in future i would need that data, instead of searching those mails i will directly go to my database and and export.

    – Aadil Shaikh
    Jan 4 at 11:40











  • @ruddra no it's not - the point is that there is absolutely NO garantee you will ever get the email, so storing the contact data ensure it won't get lost.

    – bruno desthuilliers
    Jan 4 at 14:09














1












1








1







There are many ways to do that. One of them is to override the create method of the ModelSerializer:



from django.core.mail import send_mail


class ContactCreateSerializer(ModelSerializer):
class Meta:
model = ContactForm
fields = [
'name',
'email',
'phone',
'message',
]

def create(self, validate_data):
instance = super(ContactCreateSerializer, self).create(validate_data)
send_mail(
'Instance {} has been created'.format(instance.pk),
'Here is the message. DATA: {}'.format(validate_data),
'from@example.com',
['to@example.com'],
fail_silently=False,
)
return instance


For more details on sending email, please check this documentation.



FYI: Please change your Model Name from ContactForm to Contact. Because its a model, not a form. And to be honest. You don't need to store contact information. You can do it like this:



class ContactSerailizer(Serializer):
name = serializers.CharField()
email = serializers.EmailField()
# and so on

Class ContactView(APIView):
def post(self, request, *args, **kwargs):
serailizer = ContactSerailizer(request.data)
if serailizer.is_valid():
data = serailizer.validated_data
email = validated_data.get('email')
name = validated_data.get('name')
send_mail(
'Sent email from {}'.format(name),
'Here is the message. {}'.format(validate_data.get('message')),
email,
['to@example.com'],
fail_silently=False,
)
return Response({"success": "Sent"})
return Response({'success': "Failed"}, status=status.HTTP_400_BAD_REQUEST)





share|improve this answer















There are many ways to do that. One of them is to override the create method of the ModelSerializer:



from django.core.mail import send_mail


class ContactCreateSerializer(ModelSerializer):
class Meta:
model = ContactForm
fields = [
'name',
'email',
'phone',
'message',
]

def create(self, validate_data):
instance = super(ContactCreateSerializer, self).create(validate_data)
send_mail(
'Instance {} has been created'.format(instance.pk),
'Here is the message. DATA: {}'.format(validate_data),
'from@example.com',
['to@example.com'],
fail_silently=False,
)
return instance


For more details on sending email, please check this documentation.



FYI: Please change your Model Name from ContactForm to Contact. Because its a model, not a form. And to be honest. You don't need to store contact information. You can do it like this:



class ContactSerailizer(Serializer):
name = serializers.CharField()
email = serializers.EmailField()
# and so on

Class ContactView(APIView):
def post(self, request, *args, **kwargs):
serailizer = ContactSerailizer(request.data)
if serailizer.is_valid():
data = serailizer.validated_data
email = validated_data.get('email')
name = validated_data.get('name')
send_mail(
'Sent email from {}'.format(name),
'Here is the message. {}'.format(validate_data.get('message')),
email,
['to@example.com'],
fail_silently=False,
)
return Response({"success": "Sent"})
return Response({'success': "Failed"}, status=status.HTTP_400_BAD_REQUEST)






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 4 at 9:51

























answered Jan 4 at 9:41









ruddraruddra

16.8k42951




16.8k42951













  • the mail protocol is highly unreliable - the fact the mail was "sent" doesn't garantee it will actually reach it's destination - so saving contact forms data is always a good idea (if those are of any interest to you of course - but else why bother having a contact form ?)

    – bruno desthuilliers
    Jan 4 at 10:14











  • I agree with you. But having both emails and storing data is kind of redundant, isn't it?

    – ruddra
    Jan 4 at 10:28











  • @ruddra The Answer worked for me, thanks and i know that it would be redundant to have both email and stored data. I am doing that because in future i would need that data, instead of searching those mails i will directly go to my database and and export.

    – Aadil Shaikh
    Jan 4 at 11:40











  • @ruddra no it's not - the point is that there is absolutely NO garantee you will ever get the email, so storing the contact data ensure it won't get lost.

    – bruno desthuilliers
    Jan 4 at 14:09



















  • the mail protocol is highly unreliable - the fact the mail was "sent" doesn't garantee it will actually reach it's destination - so saving contact forms data is always a good idea (if those are of any interest to you of course - but else why bother having a contact form ?)

    – bruno desthuilliers
    Jan 4 at 10:14











  • I agree with you. But having both emails and storing data is kind of redundant, isn't it?

    – ruddra
    Jan 4 at 10:28











  • @ruddra The Answer worked for me, thanks and i know that it would be redundant to have both email and stored data. I am doing that because in future i would need that data, instead of searching those mails i will directly go to my database and and export.

    – Aadil Shaikh
    Jan 4 at 11:40











  • @ruddra no it's not - the point is that there is absolutely NO garantee you will ever get the email, so storing the contact data ensure it won't get lost.

    – bruno desthuilliers
    Jan 4 at 14:09

















the mail protocol is highly unreliable - the fact the mail was "sent" doesn't garantee it will actually reach it's destination - so saving contact forms data is always a good idea (if those are of any interest to you of course - but else why bother having a contact form ?)

– bruno desthuilliers
Jan 4 at 10:14





the mail protocol is highly unreliable - the fact the mail was "sent" doesn't garantee it will actually reach it's destination - so saving contact forms data is always a good idea (if those are of any interest to you of course - but else why bother having a contact form ?)

– bruno desthuilliers
Jan 4 at 10:14













I agree with you. But having both emails and storing data is kind of redundant, isn't it?

– ruddra
Jan 4 at 10:28





I agree with you. But having both emails and storing data is kind of redundant, isn't it?

– ruddra
Jan 4 at 10:28













@ruddra The Answer worked for me, thanks and i know that it would be redundant to have both email and stored data. I am doing that because in future i would need that data, instead of searching those mails i will directly go to my database and and export.

– Aadil Shaikh
Jan 4 at 11:40





@ruddra The Answer worked for me, thanks and i know that it would be redundant to have both email and stored data. I am doing that because in future i would need that data, instead of searching those mails i will directly go to my database and and export.

– Aadil Shaikh
Jan 4 at 11:40













@ruddra no it's not - the point is that there is absolutely NO garantee you will ever get the email, so storing the contact data ensure it won't get lost.

– bruno desthuilliers
Jan 4 at 14:09





@ruddra no it's not - the point is that there is absolutely NO garantee you will ever get the email, so storing the contact data ensure it won't get lost.

– bruno desthuilliers
Jan 4 at 14:09




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54035949%2fhow-to-send-email-when-a-form-gets-submitted-django-rest-framework%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas