开发者

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

开发者 https://www.devze.com 2023-04-03 21:12 出处:网络
I am a web designer, and dont really know much about PHP. I have a form, and I want the values to be sent to three email addresses.

I am a web designer, and dont really know much about PHP. I have a form, and I want the values to be sent to three email addresses.

Here is my HTML:

<form id="player" method="post" action="process.php">

    <label for="name">Your Name</label>
    <input type="text" name="name" title="Enter your name" class="required">

    <label for="phone">Daytime Phone</label>
    <input type="tel" name="p开发者_如何学编程hone" class="required">

    <label for="email">Email</label>
    <input type="email" name="email" title="Enter your e-mail address" class="required email">


    <input type="submit" name="submit" class="button" id="submit" value="I'd like to join Now" />

</form>

I have somehow found a PHP code that should send the data to ONE email address only, but I dont even know if it works or not.

Here is the code for that:

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

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

Thanks


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 );
 ?>


You should be able to separate email addresses with commas in the first parameter of the mail() function, i.e.

mail('email1@example.com, email2@example.com', $subject, $message, $headers);

Or sepcific CC and optionally BCC addresses as per Ahmad's answer.


The mail function (which is used in the code that you posted) allows you to specify multiple recipients. See the PHP documentation of that function for details: http://php.net/manual/en/function.mail.php

Edit: You basically need to replace the "you@youremail.com" part with a list of addresses, separated by commas, e.g.:

mail("you@youremail.com,somebody@domain.com,anotherone@domain.com", ...


use

$to = "email@email.com"
$to .= ", anotheremail@email.com";

this will help you to create multiple recipient.

0

精彩评论

暂无评论...
验证码 换一张
取 消