Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send email to two addresses?

Tags:

php

email

Is it possible to send the enquiry email to two addresses with the code below? If so how would I do it?

<?php if(isset($_GET['emailme']) && $_GET['emailme'] == 'true') { 
    // to and subject
    $to = "[email protected]"; 
    $subject = "Product enquiry"; 

    // get these from query string
    $name_field = $_GET['name'];
    $hospital_field = $_GET['hospital']; 
    $department_field = $_GET['department'];
    $email_field = $_GET['email']; 
    $tel_field = $_GET['tel']; 

    // get wishlist
    $query = "SELECT w.*, p.product_name, q.quantity_name, o.product_code, o.description 
                FROM wishlistbasket w, products p, product_quantities q, product_options o 
                WHERE sesid = '$sesid' AND w.pid = p.id AND w.qid = q.id AND w.oid = o.id ORDER BY w.pid, w.qid, w.oid";
    $res = mysql_query($query);
    $wish_list = '';
    if($res){
        while($row = mysql_fetch_assoc($res)) {
            if ($row['qty'] == 1) {
                $row['qty'] = "Quote";
            } else if ($row['qty'] == 2) {
                $row['qty'] = "Sample";
            } else if ($row['qty'] == 3) {
                $row['qty'] = "Quote and Sample";
            }
            $wish_list .= $row['product_code'] . ' - ' . $row['product_name'] . ', ' . $row['quantity_name'] . ', ' . $row['qty'] . '' . $row['product_options'] . "
            \n";
        }
    }

    // build mail body
    $body = "Hello,\n\n
You have an enquiry from the website, please see the details below:\n\n 
Name: $name_field\n
Hospital/institution: $hospital_field\n
Department: $department_field\n 
E-Mail: $email_field\n 
Tel: $tel_field\n 
Wishlist:\n $wish_list"; 
    mail($to, $subject, $body); 
    echo "Thanks";} ?>
like image 373
Rob Avatar asked Jan 20 '12 09:01

Rob


People also ask

Can you send an email to multiple recipients by separating the addresses with a?

If you have a multiple recipient list, you can separate each address with a comma, semicolon, space or by pressing the enter key. Now, compose your new message and then select the Message tab and click the Send button.

How do I send to multiple email addresses in Outlook?

In the Subject box, type the subject of the message. Enter the recipients' email addresses or names in the To, Cc, or Bcc box. Separate multiple recipients with a semicolon. To select recipients' names from a list in the Address Book, click To, Cc, or Bcc, and then click the names that you want.

How do I send an email to multiple addresses without showing?

To send emails to small groups where everybody knows each other, use the Cc field. Enter all of the addresses there, separated by commas. To hide addresses, use the Bcc field, just like the Cc field. No one will be able to see the addresses added in this field.

How do I send email to multiple recipients in Gmail?

Choose your recipientsWhile in multi-send mode, you can add up to 1,500 recipients in the “To” field and a maximum of 1 recipient in the “Cc” or “Bcc” field. Any recipient added to the “Cc” or “Bcc” field will be copied on every single outgoing email.


2 Answers

mail accepts comma-separated list of recipeinets, as stated in Manual. So just set $to to something like

$to = "[email protected],[email protected]";

Refer to RFC2822 for more details on valid email address specifications.

like image 140
J0HN Avatar answered Sep 30 '22 04:09

J0HN


You could also do:


$to = "[email protected], [email protected]";
mail($to, $subject, $body);

Hope it helps

like image 44
Sudhir Bastakoti Avatar answered Sep 30 '22 05:09

Sudhir Bastakoti