Jump to content

Seeking Help with Emailing multiple addresses in PHP Contact Form


Mandolin

Recommended Posts

Hoping for some help with a small issue. I'm not a programmer but I simply need to update an existing php contact form page. A portion of the code currently looks like what I've pasted below (actual names & email addresses changed). My issue is that I need this email to be delivered to 3 recipients. How do I add a recipient, for example if I want this to go to Name1, Name2 and Name3. Any help is greatly appreciated!

$emails = array("name1" => "[email protected]", "name2" => "[email protected]", "name3" => "[email protected]", "name4" => "[email protected]");

 

  switch ($Dept)

  {

    case "Customer Service":

      $email_to = $emails['name1'] . ", " . $emails['name2'];

      break;

 

try:

<?php
$emails = array("name1" => "[email protected]", "name2" => "[email protected]", "name3" => "[email protected]", "name4" => "[email protected]");

  switch ($Dept) 
  {
    case "Customer Service":
      $email_to = $emails['name1'] . ", " . $emails['name2']. ",".$emails['name3'] ; 
      break;
?>

It might be good idea to use implode there if the amount of emails can be dynamic. E.g coming from database by certain criteria. Or if there is just huge amount of emails.

$email_to = implode($emails, ',');

 

instead of

$email_to = $emails['name1'] . ", " . $emails['name2']. ",".$emails['name3'] ; 

Worked like a charm, thanks so much!

 

 

try:

<?php
$emails = array("name1" => "[email protected]", "name2" => "[email protected]", "name3" => "[email protected]", "name4" => "[email protected]");

  switch ($Dept) 
  {
    case "Customer Service":
      $email_to = $emails['name1'] . ", " . $emails['name2']. ",".$emails['name3'] ; 
      break;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.