Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Destinatario de correo electrónico dinámico basado en la entrada de código postal para el formulario de contacto 7

Tenemos 4 Oficinas con muchos Códigos Postales asignados:

  • 21079, 22085,.... = Hamburgo
  • 10115, 10178,.... = Berlín
  • 60306, 60312,.... = Fráncfort
  • .....,......,.... = Múnich
  • todo lo demás = Oficina central

¿Es posible leer el Código Postal Ingresado desde el Formulario y enviar el Correo a la Oficina asignada de forma dinámica?

Tiene que ser dinámicamente sin un menú desplegable (en Front End) de todos los códigos postales o ciudades.

Intenté esto sin éxito

 // hook into wpcf7_before_send_mail add_action( 'wpcf7_before_send_mail', 'cf7dynamicnotifications'); // Hooking into wpcf7_before_send_mail function cf7dynamicnotifications($contact_form) // Create our function to be used in the above hook { $submission = WPCF7_Submission::get_instance(); // Create instance of WPCF7_Submission class $posted_data = $submission->get_posted_data(); // Get all of the submitted form data if( $posted_data["plz"] == '21079' ) { $recipient_email = 'office1@xyz.com'; } elseif($posted_data["plz"] == '22085') { $recipient_email = 'office2@xyz.com'; } elseif($posted_data["plz"] == '12345') { $recipient_email = 'office3@xyz.com'; } else { $recipient_email = 'head-office@xyz.com'; } // set the email address to recipient $mailProp = $contact_form->get_properties('mail'); $mailProp['mail']['recipient'] = $recipient_email; // update the form properties $contact_form->set_properties(array('mail' => $mailProp['mail'])); }

EDITAR

Gracias por tu ayuda. Mi solución funciona bien, tuve problemas con mi proveedor de correo electrónico.

Sabes como puedo ampliar el valor? Me gustaría insertar más de un valor.

Por ejemplo:

if ('21079', '21080', '21081' === $posted_data['plz'] ) { $recipient_email = 'office1@xyz.com';

Esto me da un error de sintaxis.

También esto no funcionó:

if ('21079' || '21080' || '21081' === $posted_data['plz'] ) { $recipient_email = 'office1@xyz.com';

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tu pregunta era casi correcta. El set_properties() necesita pasar toda la matriz (en su caso) $mailProp .

 /** * Dynamically Change the recipient. * * @param object $contact_form The contact form 7 contact form object. * @return void */ function cf7dynamicnotifications( $contact_form ) { $submission = WPCF7_Submission::get_instance(); // Create instance of WPCF7_Submission class. $posted_data = $submission->get_posted_data(); // Get all of the submitted form data. // Make sure the field is filled in. if ( isset( $posted_data['plz'] ) ) { if ( '21079' === $posted_data['plz'] ) { $recipient_email = 'office1@xyz.com'; } elseif ( '22085' === $posted_data['plz'] ) { $recipient_email = 'office2@xyz.com'; } elseif ( '12345' === $posted_data['plz'] ) { $recipient_email = 'office3@xyz.com'; } else { $recipient_email = 'head-office@xyz.com'; } // set the email address to recipient. $mailProp = $contact_form->get_properties( 'mail' ); $mailProp['mail']['recipient'] = $recipient_email; // update the form properties. $contact_form->set_properties( array( 'mail' => $mailProp ) ); // Pass the whole array. } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!