Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP PHP Send Email To Multiple Recipients And CC To Multiple Recipients With PHP Mailer

PHP Send Email To Multiple Recipients And CC To Multiple Recipients With PHP Mailer

In almost web application, sending email is one of most important function which helps to communicate with your customers/visitors.

This tutorial will show How to send the same message TO multiple recipients and CC to multiple recipients in one email sending process. It reduces your server resource consumption and avoid repeat the same function again and again.

Source code below uses PHPMailer as a email transport class via an Authenticated SMTP Server.

Send email and CC to multiple recipients with SMTP authentication by PHP

<?php
	include "class.smtp.php";
	include "class.phpmailer.php";
 
	$Host = "mail.yourdomain.com";						// SMTP servers
	$Username = "[email protected]";	// SMTP password
	$Password = "your-smtp-password";					// SMTP username
 
	$From = "[email protected]";
	$FromName = "From Name";
 
	$Tos = array(
		"To Name 1" => "[email protected]iddev.com",
		"To Name 2" => "[email protected]"
	);	
	$Ccs = array(
		"CC Name 1" => "[email protected]",
		"CC Name 2" => "[email protected]"
	);
 
	$Subject = "Hello there";
	$Body = "This is a test email which will send to multiple recipients";
 
	$mail = new PHPMailer();
 
    $mail->IsSMTP();                 	// send via SMTP
    $mail->Host     = $Host; 
    $mail->SMTPAuth = true;     		// turn on SMTP authentication
    $mail->Username = $Username;  
    $mail->Password = $Password; 
 
    $mail->From     = $From;
    $mail->FromName = $FromName;
	foreach($Tos as $key => $val){
		$mail->AddAddress($val , $key); 
	}
 
	foreach($Ccs as $key => $val){
		$mail->AddCC($val , $key); 
	}
 
    $mail->WordWrap = 50;				// set word wrap
	$mail->Priority = 1; 
    $mail->IsHTML(true);  
    $mail->Subject  =  $Subject;
    $mail->Body     =  $Body;
    if(!$mail->Send())
    {
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
        echo 'Message has been sent.';
    }
?>

<?php include "class.smtp.php"; include "class.phpmailer.php"; $Host = "mail.yourdomain.com"; // SMTP servers $Username = "[email protected]"; // SMTP password $Password = "your-smtp-password"; // SMTP username $From = "[email protected]"; $FromName = "From Name"; $Tos = array( "To Name 1" => "[email protected]", "To Name 2" => "[email protected]" ); $Ccs = array( "CC Name 1" => "[email protected]", "CC Name 2" => "[email protected]" ); $Subject = "Hello there"; $Body = "This is a test email which will send to multiple recipients"; $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->Host = $Host; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = $Username; $mail->Password = $Password; $mail->From = $From; $mail->FromName = $FromName; foreach($Tos as $key => $val){ $mail->AddAddress($val , $key); } foreach($Ccs as $key => $val){ $mail->AddCC($val , $key); } $mail->WordWrap = 50; // set word wrap $mail->Priority = 1; $mail->IsHTML(true); $mail->Subject = $Subject; $mail->Body = $Body; if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo 'Message has been sent.'; } ?>

Download the source code above which includes PHPMailer files

Jul 21, 2011Hoan Huynh
Show Latest People Of Facebook Fan PagePHPMailer Send Email With Attachments Via SMTP Authentication
You Might Also Like:
  • How To Track Website With Multiple Google Analytisc Accounts
  • PHPMailer Send Email With Attachments Via SMTP Authentication
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • JavaScript Alert Multiple Lines
  • Send Email Via Gmail SMTP Authentication With PHPMailer
  • Simple PHP Code Send Email
  • PHPMailer Send Email HTML Content With UTF-8 Encoding
  • Get Image Width Height With JQuery And JavaScript
  • Jquery checkbox checked
  • Javascript Problem Set focus textbox on Firefox
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

11 years ago PHPIsSMTP, PHPMailer, SMTP, SMTPAuth2,749
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
24,542 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
21,885 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
17,736 views
JQuery Allow only numeric characters or only alphabet characters in textbox
15,059 views
C# Read Json From URL And Parse/Deserialize Json
11,789 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Things to Learn about Installingderm Loan Type S
  • Online Photo Editor – Free Photoediting Software
  • A Guide to Finding the Best Paper Sellers
  • Photoediting in Home Isn’t Hard to Do!

  • Free Photo Editor Online
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (27)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (647)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development