2
我有一個人們可以提交電子郵件的頁面。它有效,但我收到所有來自它的電子郵件,說它們來自我自己。在django發送電子郵件。
這裏的觀點:
def signup(request):
if request.method == 'POST': # If the form has been submitted...
form = SignUpForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
sender = form.cleaned_data['sender']
recipients = ['[email protected]']
from django.core.mail import send_mail
send_mail(subject, message, sender, recipients)
return HttpResponseRedirect('/thanks/') # Redirect after POST
else:
form = SignUpForm() # An unbound form
return render_to_response('signup.html', {'form': form,},context_instance=RequestContext(request))
而且設置:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
MANAGERS = ADMINS
你試過用關鍵字?即'send_mail(subject = subject,message = message,from_email = sender,recipient_list = recipients)'只需進行一次完整性檢查,它應該按原樣工作。 – Hannele 2012-04-14 16:47:09
不起作用它說我從我自己發送它 – 2012-04-14 16:59:43
那麼,'收件人'是你,發件人也是你。那麼,它不應該是'你'嗎? – CppLearner 2012-04-14 17:54:37