How to send same email to multiple recipients using php

Please look at the code below. I would like to send the same info to m

Page 1 of 1

4 Replies - 16042 Views - Last Post: 14 May 2008 - 08:55 PM Rate Topic: -----

#1 Romu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-May 08

How to send same email to multiple recipients using php

Post icon  Posted 14 May 2008 - 09:43 AM

Below is the part of code thats sends a confirmation email to the registered user. I would like to send the same email to 2 more mail ids. If I add more than one email id to To: mail is being sent to only the first id though the next two email ids are visible in the To: section in the mail sent to the first id. Cc: and Bcc: also do not help.

Please help me.



 /* if (! send_confirmation_email($user)) {
				error("Tried to send you an email but failed!");
			}*/
			$smtp=new smtp_class;
			$domain="128.313.35.97";
			$message="Thanks for registering. Please confirm by clicking the link";
			$port=0;
			$resolve_message=30;
			//echo "Value is".$smtp->Connect($domain);
			$from1="kplamelu@gmail.com";
			//echo $user->email;
			
			$site = get_site();
	$from = get_admin();

	$data->firstname = fullname($user);
	$data->sitename = $site->fullname;
	$data->admin = fullname($from) .' ('. $from->email .')';
	$data->link = $CFG->wwwroot .'/login/confirm.php?p='. $user->secret .'&s='. $user->username;
	$message = get_string('emailconfirmation', '', $data);
	//echo "message is".$message;
			 if($smtp->SendMessage($from1,array($user->email),array("From: $from1",
			"To: $user->email",
			"Subject:  Registration confirmation",
			"Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")
		),
		$message
			 ))
			 echo "";
	   // echo "Message has been sent to your email address Please check your email and follow directions to confirm"; 
			 else
		echo "Cound not send the message to $to.\nError: ".$smtp->error."\n";
	
			$emailconfirm = get_string("emailconfirm");
			print_header($emailconfirm, $emailconfirm, $emailconfirm);
			notice(get_string("emailconfirmsent", "", $user->email), "$CFG->wwwroot/");
			exit;
		}
	}



** Edit ** :code:

This post has been edited by no2pencil: 14 May 2008 - 08:53 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How to send same email to multiple recipients using php

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4438
  • View blog
  • Posts: 12,310
  • Joined: 18-April 07

Re: How to send same email to multiple recipients using php

Posted 14 May 2008 - 11:24 AM

Well I guess it depends on how you are going about adding the other two email addresses. You are also going to need to make some changes in the SendMessage() method of whatever class $smtp is set to. SendMessage will have the php mail() call in it most likely and it appears they have wrapped it up in SendMessage.

SendMessage is taking arrays (as parameters) there so you will first have to see how SendMessage works and puts the parameters into mail() and then either add the second and third emails to the array that is passed to SendMessage or hardcode them in the SendMessage function.

Naturally I would see how SendMessage works and try to pass them into the function through the array parameters, but if that is too difficult for you to do then hardcode might be the quick and dirty way of doing it (especially if the email addresses don't change).

If you continue to have trouble, show us the SendMessage function that is called from the code you just showed us above. From there we can then tell you how to modify both the script above and if necessary the SendMessage function.

:)
Was This Post Helpful? 0
  • +
  • -

#3 Akelo  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 98
  • Joined: 12-December 07

Re: How to send same email to multiple recipients using php

Posted 14 May 2008 - 03:28 PM

Hey Martyr, question about that, I know the function for sending mail is dead simple, but I could understand some confusion on sending multiple emails to different addresses.

let's say in your email webpage, you have the To: box and they put in email1@test.com, email2@test.com and so forth, each seperated by a comma,
I would use the explode() php function to seperate them, then could use a foreach loop to send the email out to each person, with the message being a repeat of what was typed. Is that what you're suggesting or is there a better way?
Was This Post Helpful? 0
  • +
  • -

#4 2457  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 72
  • Joined: 09-April 08

Re: How to send same email to multiple recipients using php

Posted 14 May 2008 - 05:34 PM

well that should do the trick.
At least for me it seams a good solution.
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5413
  • View blog
  • Posts: 27,429
  • Joined: 10-May 07

Re: How to send same email to multiple recipients using php

Posted 14 May 2008 - 08:55 PM

This Tutorial that I wrote uses a variable for the to field. You could simply put in as many email addresses that you like, & it will go to them. I am pretty certain you will need to separate them with a semicolon.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1