Rails ActionMailer - format sender and recipient name/email address

后端 未结 6 1237
耶瑟儿~
耶瑟儿~ 2020-12-04 09:44

Is there a way to specify email AND name for sender and recipient info when using ActionMailer?

Typically you\'d do:

@recipients   = \"#{user.email         


        
6条回答
  •  天命终不由人
    2020-12-04 09:56

    If you are taking user input for name and email, then unless you very carefully validate or escape the name and email, you can end up with an invalid From header by simply concatenating strings. Here is a safe way:

    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 "
    

提交回复
热议问题