我在 Google Apps Engine、Python 上托管我的网站,我正在尝试处理一个简单的联系表单。
这是我的 HTML:
<form method="post" action="/email" id="contactForm">
<h2>Let's get in touch!</h2>
Name:<br/>
<input size=35 name="name" placeholder="Feature coming soon!"><br/>
Email:<br/>
<input size=35 name="email" placeholder="Feature coming soon!"><br/>
Subject:<br/>
<input size=35 name="subject" placeholder="Feature coming soon!"><br/>
Message:<br/>
<textarea name="message" rows=15 cols=50 placeholder="Feature coming soon!"></textarea><br/>
<input type="submit" name="send" value="Submit">
</form>
在我的 app.yaml 中:
- 网址:/电子邮件
脚本:email.py
这是我的 email.py:
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import mail
class SendEmail(webapp.RequestHandler):
def post(self):
name = self.request.post("name")
email = self.request.post("email")
tempSubject = self.request.post("subject")
msg = self.request.post("body")
if name is None:
self.response.out.write("Error: You did not enter a name.")
elif email is None:
self.response.out.write("Error: You did not enter an email.")
elif tempSubject is None:
self.response.out.write("Error: You did not enter a subject.")
elif msg is None:
self.response.out.write("Error: You did not enter a message.")
else:
_subject = "Msg from: " + name + "Re: " + tempSubject
message = mail.EmailMessage(sender = "alexyoung1992@alexyoung.us", to = "alexyoung1992@gmail.com", subject = _subject, body = msg, reply_to = email)
message.send()
application = webapp.WSGIApplication([('/email', SendEmail)], debug=True)
run_wsgi_app(application)
self.redirect('/')
我收到 500 服务器错误:
错误:服务器错误
服务器遇到错误,无法完成您的请求。如果问题仍然存在,请报告您的问题并提及此错误消息和导致它的查询。
编辑:我更新了我的 Python 脚本并在我的本地机器上调试了所有它。一切运行顺利,但是一旦我尝试在服务器上运行它,我就会遇到同样的错误。你们也可以尝试自己运行脚本,看看是否有任何不同。