0

I created a contact form in Symfony2. I would like to send it via email and also i want to save the content in the database via Symfony2, for this i created a form. The saving into the database works fine but I never get an email on the production server.

public function createAction(Request $request) {
    $entity = new Contact();
    $form = $this -> createCreateForm($entity);
    $form -> handleRequest($request);

    $message = \Swift_Message::newInstance() -> setSubject('Hello Email') -> setFrom('newsletter@donaci.ch') -> setTo('me@joelschmid.ch') -> setBody($this -> renderView('DbeDonaciBundle:Contact:email.html.twig', array('entity' => $entity)));
    $this -> get('mailer') -> send($message);


    $em = $this -> getDoctrine() -> getManager();
    $em -> persist($entity);
    $em -> flush();

    $this -> get('session') -> getFlashBag() -> add('messageSent', 'Die Nachricht wurde erfolgreich abgeschickt. Wir werden uns sobald als möglich bei dir melden!');



    return $this -> render('DbeDonaciBundle:Aboutus:index.html.twig', array('entity' => $entity, 'form' => $form -> createView(), ));
}

Locally this seems to work, if I access the message block in the developer toolbar I have an email ready:

    Mailer default (default mailer)

Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=utf-8
MIME-Version: 1.0
Date: Tue, 04 Mar 2014 10:54:07 +0100
Message-ID: <725cbd36eaafdc75ede3eeb016a60b1d@localhost>
From: newsletter@donaci.ch
Subject: Hello Email
To: me@joelschmid.ch
A contact enquiry was made by asdf at 2014-03-04 10:54.

Reply-To: asdf@memememe.com
Subject: asdf
Body:
Name: asdf
E-Mail: asdf@memememe.com
Message: asdf 
Website: asdf

Also there is no e-mail in the spool if I execute:

php app/console swiftmailer:spool:send

Here is the adjusted configfile with mailjet:

mailer_transport: smtp 
mailer_host: in.mailjet.com 
mailer_user: 3d32164c00c29asdflkjabf2d1e45b 
mailer_password: 342f84sdaj7a3d374eb85523dfad246 
locale: en 
secret: 34af84cbbb7a3d12li552cfgad246

Any ideas? Thanks in advance for your help guys!

joelschmid
  • 828
  • 1
  • 16
  • 32
  • mailer_transport: smtp mailer_host: in.mailjet.com mailer_user: 70a0a2164c00c29asdflkjabff39dd7e45b mailer_password: f6baf84sdaj7a3d374eb8552ccfad246 locale: en secret: f6baf84cbbb7a3d12li552ccfad246 – joelschmid Mar 05 '14 at 08:05

1 Answers1

1

it should be relative to smtp server : if symfony debug shows you the mail, it's definetly this.

Try using a dedicated smtp service such as mailjet ( www.mailjet.com ) to handle your emails sending .

Charles-Antoine Fournel
  • 1,713
  • 1
  • 25
  • 37
  • I Changed the parameters.yml file, is it correct with mailjet.com? mailer_transport: smtp mailer_host: in.mailjet.com mailer_user: 70a0a2164c00c29asdflkjabff39dd7e45b mailer_password: f6baf84sdaj7a3d374eb8552ccfad246 locale: en secret: f6baf84cbbb7a3d12li552ccfad246 – joelschmid Mar 05 '14 at 06:50
  • yes that's correct ( unless you did wrong for mailer_user and mailer_password : )) . you don't have specify a port ( it works for me ) . Be sure to check your mailjet accoun after sending your first email , because you ll have to confirm the sender's mail in order to validate mails ( it's a security thing to prevent spam ) – Charles-Antoine Fournel Mar 05 '14 at 09:06
  • I added the port, mailer_port: 587 But there is still no email in the mailjet. is the config file as it is on the posted question really correct? do i need to add an parameter? auth? – joelschmid Mar 05 '14 at 12:44
  • on my multiple configuration i never set the mailer_port with mailjet because it throws an error in symfony. I directly set the value in my config.yml file like this : # Swiftmailer Configuration swiftmailer: transport: "%mailer_transport%" host: "%mailer_host%" username: "%mailer_user%" password: "%mailer_password%" port: "587" spool: { type: memory – Charles-Antoine Fournel Mar 05 '14 at 13:22
  • @Schmid does it works now or do you need more help ? – Charles-Antoine Fournel Mar 05 '14 at 17:26
  • Sadly it doesn't work yet. But thanks already for your help!! I realy appreciate it! I even tried gmail, but I get the following message: Connection could not be established with host smtp.gmail.com [ #0] It seams that my provider blocks the 587 port but if it is like that why don't i receive an error message with the mailjet ? are the configurations in the parameters.yml really correct? – joelschmid Mar 06 '14 at 08:12
  • 1
    if you didn't receive an error , may be there is no error at all , did you check emails in https://fr.mailjet.com/account/sender ? – Charles-Antoine Fournel Mar 06 '14 at 09:25
  • it works now, i didn't activate it in mailjet i guess *ashamed* THanks a lot! – joelschmid Mar 06 '14 at 12:37
  • @Schmid it happened to me twice :) – Charles-Antoine Fournel Mar 06 '14 at 14:28