PHP Form Send Email to Multiple Recipients

PHP form send email to multiple recipients

This will work:

$email_to = "jhewitt@amleo.com,some@other.com,yet@another.net";

PHP Send-Mail form to multiple email addresses

You implode an array of recipients:

$recipients = array('jack@gmail.com', 'jill@gmail.com');

mail(implode(',', $recipients), $submit, $message, $headers);

See the PHP: Mail function reference - http://php.net/manual/en/function.mail.php

Receiver, or receivers of the mail.

The formatting of this string must comply with » RFC 2822. Some examples are:

  • user@example.com
  • user@example.com, anotheruser@example.com
  • User <user@example.com>
  • User <user@example.com>, Another User <anotheruser@example.com>

How to send form data to multiple email addresses using PHP?

Add headers

 <?php
// Get Data
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$url = strip_tags($_POST['url']);
$message = strip_tags($_POST['message']);

$headers .="From: Forms <forms@example.net>";
$headers .="CC: Mail1 <Mail1@example.net>";
$headers .=", Mail2 <Mail2@example.net>";

// Send Message
mail( "you@youremail.com", "Contact Form Submission",
"Name: $name\nEmail: $email\nPhone: $phone\nWebsite: $url\nMessage: $message\n",
$headers );
?>

Sending emails to multiple addresses using config PHP file and PHP Mailer

Based on the examples from PHPMailer courtesy of the link shared by @Chris Haas. I made these changes:

<?php
$config = [
"host" => "xxx",
"username" => "xxx",
"password" => "xxx",
"secure" => "ssl", // ssl or tls
"port" => 465,
"sendTo" => "abc@email.com",
"sendTo2" => "efg@email.com",
"sendTo3" => "hik@email.com",
"sendToBCC" => "xyz@email.com",
"from" => "no-reply@email.com",
"fromName" => "Contact Form"
];

And in the sending file I did this:

//Recipients
$mail->setFrom($config['from'], $config['fromName']);
$mail->addAddress($config['sendTo']);
$mail->addAddress($config['sendTo2']);
$mail->addAddress($config['sendTo3']);
$mail->addCC($config['sendToCC']);
$mail->addBCC($config['sendToBCC']);
$mail->addAddress($_POST['email']);

That resolved the issue.

PHP mail: Multiple recipients?

while($row = mysql_fetch_array($result))
{
$addresses[] = $row['address'];
}
$to = implode(", ", $addresses);

As specified on the mail() manual page, the "to" parameter of the function can take a comma-separated list of addresses.



Related Topics



Leave a reply



Submit