提问人:Maxence Audibert 提问时间:10/31/2023 更新时间:11/10/2023 访问量:29
已提交联系表格,但我没有收到任何电子邮件:(
Contact form submitted but I don't receive any email :(
问:
当我填写表格时,它被发送了,但我没有在我的 gmail 帐户中收到它
我在我的 Ruby 应用程序中使用联系人邮件创建了控制器和视图。
以下是 contact.html.erb 代码:
<div class="contact-form">
<form action="/contact" method="post">
<div class="contact-form-grid-2">
<div class="form-group">
<label for="nom">Nom</label>
<input type="text" id="nom" name="nom" required>
</div>
<div class="form-group">
<label for="mail">Email</label>
<input type="email" id="mail" name="mail" required>
</div>
<div class="form-group">
<label for="telephone">Téléphone</label>
<input type="tel" id="telephone" name="telephone" required>
</div>
<div class="form-group">
<label for="expertise">Expertises</label>
<select id="expertise" name="expertise[]" class="form-group" multiple>
<option value="famille">Famille</option>
<option value="placement">Placement</option>
<option value="entrepreneurs">Entrepreneurs</option>
<option value="emprunt">Emprunt</option>
<option value="assistance">Assistance Administrative</option>
<option value="impots">Fiscalité</option>
</select>
</div>
<div class="form-group" style="grid-column: span 2;"> <!-- Permet au champ de message de prendre toute la largeur -->
<label for="message">Message</label>
<textarea id="message" name="message" class="wide-input" placeholder="Message" required style="font-weight: lighter;"></textarea>
</div>
<div class="button-form-block">
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token%>">
<input type="submit" name="commit" value="ENVOYER" class="button-form">
</div>
</div> <!-- Bouton sous le champ de message -->
</form>
</div>
</div>
</div>
下面是接触控制器:
class ContactController < ApplicationController
def new
end
def create
nom = params[:nom]
email = params[:mail]
telephone = params[:telephone]
expertises = params[:expertise]
message = params[:message]
# Envoi du message par e-mail
ContactMailer.contact_email(nom, email, telephone, expertises, message).deliver_now
# Redirigez l'utilisateur vers une page de confirmation
redirect_to contact_confirmation_path
end
def confirmation
render template: 'contact/_confirmation'
end
end
这是联系邮件控制器:
class ContactMailer < ApplicationMailer
default from: 'MY EMAIL'
def contact_email(nom, email, telephone, expertises, message)
@nom = nom
@email = email
@telephone = telephone
@expertises = expertises
@message = message
mail(to: 'MY EMAIL', subject: 'new message from the website XX')
end
end
我在development.rb文件中有它:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
user_name: ENV['GMAIL_USERNAME'],
password: ENV['GMAIL_PASSWORD'],
authentication: 'plain',
enable_starttls_auto: true
}
谢谢你的帮助!
答:
0赞
Kinley Wangchuk
11/10/2023
#1
mail(to: 'MY EMAIL', subject: 'new message from the website XX')
应该是
mail(to: @email, subject: 'new message from the website XX')
? 如果可以共享错误(如果有),那就更好了。
评论