在使用ActionMailer时,有没有办法为发件人和收件人信息指定电子邮件和名称?
通常你会这样做:
@recipients = "#{user.email}"
@from = "info@mycompany.com"
@subject = "Hi"
@content_type = "text/html"
但是,我还想指定名称-- MyCompany <info@mycompany.com>
、John Doe <john.doe@mycompany>
。
有没有办法做到这一点?
发布于 2011-11-13 01:55:30
如果您接受用户输入的姓名和电子邮件,那么除非您非常小心地验证或转义姓名和电子邮件,否则只需连接字符串就可以得到一个无效的From标头。这里有一个安全的方法:
require 'mail'
address = Mail::Address.new email # ex: "john@example.com"
address.display_name = name.dup # ex: "John Doe"
# Set the From or Reply-To header to the following:
address.format # returns "John Doe <john@example.com>"
发布于 2009-06-05 18:49:17
@recipients = "\"#{user.name}\" <#{user.email}>"
@from = "\"MyCompany\" <info@mycompany.com>"
发布于 2011-02-23 05:47:40
在rails3中,我在每个环境中放置了以下内容。即production.rb
ActionMailer::Base.default :from => "Company Name <no-reply@production-server.ca>"
在Rails3中,在公司名称周围加引号对我来说不起作用。
https://stackoverflow.com/questions/957422
复制相似问题