hai frnds......how can i sent mail to multiple mailaddresses at a time? you have any script abt this.. so, plz help me.....

Dani AI

Generated

Quick correction and practical advice building on and : addresses must be passed to PHP as a single comma-separated string or added via headers (To/Bcc). The example in reply #2 uses invalid PHP syntax. A reliable workflow is to collect recipients in an array, validate and sanitize each address, then join them into the recipient string before calling mail(). See the official mail() reference for behavior and parameter details: PHP mail() documentation.

Example patterns (validate first, then join):

$emails = array('alice@example.com', 'bob@example.com', 'carol@example.com');
$to = implode(', ', $emails);
mail($to, $subject, $message, $headers);

Sanitize to prevent header injection and drop invalid addresses:

$clean = array();
foreach ($emails as $e) {
    $e = trim($e);
    $e = str_replace(array("\r","\n","%0a","%0d"), '', $e);
    if (filter_var($e, FILTER_VALIDATE_EMAIL)) {
        $clean[] = $e;
    }
}
$to = implode(', ', $clean);

Notes and cautions: is correct that Bcc hides recipients, but headers must contain plain addresses (no HTML mailto anchors) and must be sanitized. For authenticated SMTP, better deliverability, attachments, and larger mailing needs, use a maintained library such as PHPMailer. Also be aware of host/ISP limits and avoid sending very large batches in a single mail() call.

Recommended Answers

All 2 Replies

you just need to add a comma between the email addresses.

e.g.

$to = "example@domain.com", "example2@domain.com";

you can add the bcc field in the headers part of the mail function.
$headers .= "Bcc:,"; etc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.