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" => "name1@domain.com", "name2" => "name2@domain.com", "name3" => "name3@domain.com", "name4" => "name4@domain.com");

 

  switch ($Dept)

  {

    case "Customer Service":

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

      break;

 

Link to comment
Share on other sites

try:

<?php
$emails = array("name1" => "name1@domain.com", "name2" => "name2@domain.com", "name3" => "name3@domain.com", "name4" => "name4@domain.com");

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

Link to comment
Share on other sites

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'] ; 

Link to comment
Share on other sites

Worked like a charm, thanks so much!

 

 

try:

<?php
$emails = array("name1" => "name1@domain.com", "name2" => "name2@domain.com", "name3" => "name3@domain.com", "name4" => "name4@domain.com");

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.