Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Allow contact us email to be sent to Super Admins #44

Merged
merged 5 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions contacts/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.views import View
from django.conf import settings
from django.core.mail import send_mail
from django.contrib.auth.models import User
from django.shortcuts import render, redirect

from .forms import ContactForm
Expand All @@ -20,13 +21,21 @@ def post(self, request):

subject = form.cleaned_data.get('subject', '')
message = form.cleaned_data.get('message', '')
email_from = settings.NOREPLY_EMAIL
email_from = settings.EMAIL_HOST_USER
name = form.cleaned_data.get('name', '')
# Send email to yourself or any other recipient
recipient_list = [settings.EMAIL_HOST_USER]
recipient_list = User.objects.filter(
is_superuser=True).values_list('email', flat=True)

message = f"Name: {name}\n\n{message}"

# Sending email
send_mail(subject, message, email_from, recipient_list)

# Debugging email
print("Email From:", email_from)
print("Recipient List:", recipient_list)

return redirect('contacts:contact')

context = {'form': form}
Expand Down
4 changes: 2 additions & 2 deletions yummy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

# Send Email to Gmail
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

# Send Email to Gmail
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587 # Gmail SMTP port
EMAIL_USE_TLS = True
EMAIL_HOST_USER = env("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = env("EMAIL_HOST_PASSWORD")
NOREPLY_EMAIL = 'noreply@yummy.com.my'

ALLOWED_HOSTS = [
'0.0.0.0',
Expand Down
Loading