我在python中编写了一个简单的电子邮件脚本,它从表单中获取数据并使用boto通过电子邮件发送。我现在需要做的是将用户重定向到另一个页面“thankyou.html”而不显示任何cgi输出。
HTML表格:
<form method="post" action="/cgi-bin/iemail.py">
<div class="row uniform 50%">
<div class="6u 12u$(xsmall)">
<input type="text" name="name" id="name" value="" placeholder="Name" required="required"/>
</div>
<div class="6u 12u$(xsmall)">
<input type="text" name="company" id="company" value="" placeholder="Company Name" required="required"/>
</div>
<div class="6u 12u$(xsmall)">
<input type="text" name="phone" id="phone" value="" placeholder="Phone Number" required="required"/>
</div>
<div class="6u$ 12u$(xsmall)">
<input type="email" name="email" id="email" value="" placeholder="Email" required="required"/>
</div>
<div class="12u$">
<div class="select-wrapper">
<select name="category" id="category">
<option value="">- Category -</option>
<option value="Additional Information">Additional Information</option>
<option value="Services Request">Services Request</option>
<option value="Consulting Request">Consulting Request</option>
<option value="Development Request">Development Request</option>
<option value='Support Request'>Support Request</option>
</select>
</div>
</div>
<div class="4u 12u$(small)">
<input type="radio" id="priority-low" name="priority" checked>
<label for="priority-low">Low</label>
</div>
<div class="4u 12u$(small)">
<input type="radio" id="priority-normal" name="priority">
<label for="priority-normal">Normal</label>
</div>
<div class="4u$ 12u$(small)">
<input type="radio" id="priority-high" name="priority">
<label for="priority-high">High</label>
</div>
<div class="12u$">
<textarea name="message" id="message" placeholder="Enter your message" rows="6" required="required"></textarea>
</div>
<div class="6u 12u$(small)">
<!--<input type="checkbox" id="demo-copy" name="demo-copy">
<label for="demo-copy">Email me a copy</label>
</div>-->
<div class="6u$ 12u$(small)">
<input type="checkbox" id="human" name="human" required="required">
<label for="human">Not a robot</label>
</div>
<div class="12u$">
<ul class="actions">
<li><input type="submit" value="Send Message" class="special" /></li>
<input type="hidden" name="redirect" value="index.html" />
<li><input type="reset" value="Reset" /></li>
</ul>
</div>
</div>
</form>
Python脚本:
#!/usr/bin/python2.7
import cgi
import html
import boto.ses
import cgitb; cgitb.enable() #for troubleshooting
print("Content-Type: text/html")
print
def getdata():
form = cgi.FieldStorage()
name = form["name"].value
company = form["company"].value
phone = form["phone"].value
email = form["email"].value
category = form["category"].value
message = form["message"].value
return name, company, phone, email, category, message
#main Program
if __name__=="__main__":
try:
name, company, phone, email, category, message = getdata()
conn = boto.ses.connect_to_region('us-west-2')
conn.send_email(
'admin@gmail.com',
category,
'%r, %r, %r, %r %r' % (email, name, company,
phone, message),
to_addresses = 'admin@gmail.com'
)
except:
cgi.print_exception()
我只能重定向到cgi脚本的输出,我需要将客户发送到thankyou.html