使用cpanel python应用程序不会发送电子邮件
由于NGINX服务器上的域问题,我正在尝试将cpanel python应用程序用于我的python应用程序 我已经安装了python应用程序,并安装了运行该应用程序的所有模块。应用程序运行正常,但在联系人页面上,当我尝试发送联系人表单信息时,我收到一个500内部服务器错误 代码在NGINX服务器上运行得非常好。为了让代码在cpanel中的python应用程序上运行,我确实需要做一些更改,但它只是main.py文件中的passenger_wsgi.py文件和app.run文件 下面是我的app.py(主python文件)代码 这是form.py代码使用cpanel python应用程序不会发送电子邮件,python,email,module,cpanel,contact-form,Python,Email,Module,Cpanel,Contact Form,由于NGINX服务器上的域问题,我正在尝试将cpanel python应用程序用于我的python应用程序 我已经安装了python应用程序,并安装了运行该应用程序的所有模块。应用程序运行正常,但在联系人页面上,当我尝试发送联系人表单信息时,我收到一个500内部服务器错误 代码在NGINX服务器上运行得非常好。为了让代码在cpanel中的python应用程序上运行,我确实需要做一些更改,但它只是main.py文件中的passenger_wsgi.py文件和app.run文件 下面是我的app.p
from flask_wtf import Form
from wtforms import StringField, TextAreaField, SubmitField
from wtforms.validators import DataRequired, Email
class ContactForm(Form):
full_name = StringField('Name', validators=[DataRequired('Please add your name')])
email = StringField('Email',
validators=[DataRequired('Please enter your email'), Email('Please enter a valid email')])
subject = StringField('Subject', validators=[DataRequired('Please enter the subject of this email')])
company = StringField('Company', validators=[DataRequired('Please enter your company name')])
message = TextAreaField('message', validators=[DataRequired('Please enter a message')])
submit = SubmitField("Send")
这是“联系我们”页面上的表格
<div class="card-body form">
{% if success %}
<p class="lead text-success">Thank you for feedback !</p>
{% endif %}
<form method="post" action="{{ url_for('contact_us') }}">
<div class="row">
<div class="col-md-6">
<div class="md-form mb-0">
{% for error in form.full_name.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
{{ form.full_name(class='form-control', id='form-contact-name') }}
{{ form.full_name.label(for='form-contact-name') }}
</div>
</div>
<div class="col-md-6">
<div class="md-form mb-0">
{% for error in form.email.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
{{ form.email(class='form-control', id='form-contact-email') }}
{{ form.email.label(for='form-contact-email') }}
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="md-form mb-0">
{% for error in form.company.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
{{ form.company(class='form-control', id='form-contact-company') }}
{{ form.company.label(for='form-contact-company') }}
</div>
</div>
<div class="col-md-6">
<div class="md-form mb-0">
{% for error in form.subject.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
{{ form.subject(class='form-control', id='form-contact-subject') }}
{{ form.subject.label(for='form-contact-subject') }}
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="md-form mb-0">
{% for error in form.message.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
{{ form.message(class='form-control md-textarea', id='form-contact-message') }}
{{ form.message.label(for='form-contact-message') }}
<div class="text-center text-md-left">
{{ form.submit(class='btn btn-sm rounded btn-primary') }}
</div>
</div>
</div>
</div>
</form>
</div>
{%if success%}
感谢您的反馈
{%endif%}
{%form.full_name.errors%}
[{{error}}]
{%endfor%}
{{form.full_name(class='form-control',id='form-contact-name')}
{{form.full_name.label(for='form-contact-name')}
{%form.email.errors%}
[{{error}}]
{%endfor%}
{{form.email(class='form-control',id='form-contact-email')}
{{form.email.label(for='form-contact-email')}
{%form.company.errors%}
[{{error}}]
{%endfor%}
{{form.company(class='form-control',id='form-contact-company')}
{{form.company.label(for='form-contact-company')}
{form.subject.errors%中的错误为%s}
[{{error}}]
{%endfor%}
{{form.subject(class='form-control',id='form-contact-subject')}
{{form.subject.label(for='form-contact-subject')}
{%form.message.errors%}
[{{error}}]
{%endfor%}
{{form.message(class='form-control-md textarea',id='form-contact-message')}
{{form.message.label(for='form-contact-message')}
{{form.submit(class='btn btn sm rounded btn primary')}
我将电子邮件和密码更改为示例。没有错误日志或代码,仅在单击“发送”按钮后显示500个内部服务器错误。除此之外,该应用程序的其他所有内容都可以很好地加载
如果有关于这个问题的任何文档,那就太好了。我已经在谷歌上搜索了大约4天,现在找不到任何关于这个问题或如何让它工作的可靠信息。设法解决了这个问题,Cpanel不允许用户form.email.data作为发件人。所以我不得不把它改成实际的发件人电子邮件info@example.com. 我添加了一个回复,这样你就可以回复客户了 我还必须改变配置
app.config["SECRET_KEY"] = "Long Secret Key"
app.config["MAIL_SERVER"] = "mail.example.com"
app.config["MAIL_PORT"] = 25
app.config["MAIL_USE_SSL"] = False
app.config["MAIL_USERNAME"] = 'info@example.com'
app.config["MAIL_PASSWORD"] = 'password'
@app.route('/contact_us', methods=['GET', 'POST'])
def contact_us():
form = ContactForm()
if request.method == 'POST':
msg = Message(form.subject.data, sender=("Contact Form", "info@example.com"), recipients=['info@example.com'], reply_to=form.email.data)
msg.body = """
From: %s
Email: %s
Company Name: %s
Message: %s
""" % (form.full_name.data, form.email.data, form.company.data, form.message.data)
mail.send(msg)
return render_template('contact_us.jinja2', success=True, form=form)
elif request.method == 'GET':
return render_template('contact_us.jinja2', form=form)
添加回溯
app.config["SECRET_KEY"] = "Long Secret Key"
app.config["MAIL_SERVER"] = "mail.example.com"
app.config["MAIL_PORT"] = 25
app.config["MAIL_USE_SSL"] = False
app.config["MAIL_USERNAME"] = 'info@example.com'
app.config["MAIL_PASSWORD"] = 'password'
@app.route('/contact_us', methods=['GET', 'POST'])
def contact_us():
form = ContactForm()
if request.method == 'POST':
msg = Message(form.subject.data, sender=("Contact Form", "info@example.com"), recipients=['info@example.com'], reply_to=form.email.data)
msg.body = """
From: %s
Email: %s
Company Name: %s
Message: %s
""" % (form.full_name.data, form.email.data, form.company.data, form.message.data)
mail.send(msg)
return render_template('contact_us.jinja2', success=True, form=form)
elif request.method == 'GET':
return render_template('contact_us.jinja2', form=form)