Python的新手。
我正在尝试使用Python为我的投资组合网站创建联系表格。该表单具有4个输入字段-first_name,last_name,email和message。我的网站由hostgator.com托管。
我希望在提交表格时将我在4个字段中提供的信息简单地发送给我指定的电子邮件。
[经过大量搜索后,我看到了很多Django tut,但是我只想使用Python编写一个简单的表单。
任何帮助将不胜感激! -Mike Rossi
#!/usr/bin/python
# Import modules from CGI handling
import cgi, cgitb, smtplib
cgitb.enable()
# Create instance of FieldStorage
form = cgi.FieldStorage()
print("")
# Get data from fields
first_name = form.getvalue("first_name")
last_name = form.getvalue("last_name")
email = form.getvalue("email")
message = form.getvalue("message")
to = "[email protected]"
subject = "Comment from MikeTheDev.com"
mfrom msg['To']
to msg['Subject']
form['subject'].value
print("Thanks for contacting me! Get back to you soon,%s. ") % cgi.escape(first_name)
由于OP在3年前发布,我在尝试在我的投资组合网站上建立联系页面时遇到了这个问题。遇到此问题后,我找到了以下链接:https://code.tutsplus.com/tutorials/intro-to-flask-adding-a-contact-page--net-28982。这应该可以回答您的问题。