Phoenix: Sending email via SendGrid not delivered

I need to send contact form details as email. So far, everything seems to work fine from the application end in the sense that, I don’t get any contrary messages when I hit the send button. However the email doesn’t arrive in the receipients in box.

Below are the specific code pertaining to the contact form/email:

mix.exs

def application do
    [mod: {MyApp, []},
     applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext,
                    :phoenix_ecto, :postgrex, :bamboo]]
  end

  defp deps do
    [{:phoenix, "~> 1.2.0"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.0"},
     {:postgrex, ">= 0.0.0"},
     {:phoenix_html, "~> 2.6"},
     {:phoenix_live_reload, "~> 1.0", only: :dev},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"},
     {:bamboo, "~> 0.7"},
     {:bamboo_smtp, "~> 1.2.1"}]
  end

config.exs

config :my_app, MyApp.Mailer,
  adapter: Bamboo.SendgridAdapter,
  api_key: "my sendgrid api_key"

page_controller.ex

defmodule MyApp.PageController do
  use MyApp.Web, :controller

  alias MyApp.Contact
  alias MyApp.Mailer
  alias Email

  def contact(conn, contact_params) do
      changeset = Contact.changeset(%Contact{}, contact_params)
      if changeset.valid? do
          Email.contact_us_text_email(contact_params[:email]) |> Mailer.deliver_now
      end
      render conn, "contact.html", changeset: changeset
  end
end

mailer.ex

defmodule MyApp.Mailer do
  use Bamboo.Mailer, otp_app: :my_app
end

email.ex

defmodule Email do
    use Bamboo.Phoenix, view: MyApp.EmailView

  def contact_us_text_email(email) do
    new_email
    |> to("my_email@gmail.com")
    |> from(email)
    |> subject("Test Email!")
    |> text_body("Test Message")
  end
end

Am I doing anything wrong?

Your controller will render whether the changeset is valid or not but the email will only send it the change set is valid. Are you sure the changeset is valid?

Andrew