Jump to content

Sending emails using array values


nottoolate

Recommended Posts

I have a form that allows a user to select from several dropdowns, employees who will receive an email message.

The email script works fine, however if an employee is selected more than once (which is not a rare) then the employee will receive as many email messages as their name appears.

I would like for each employee to only receive the email once.

 

For example:

I am the submitter of the form and I am also the coordinator for this particular job. Therefore, my name & email are in the array twice and I will receive two emails on submit.

 

Here is my email script:

 

             $submitter = get_employee_email($user_id);
		$project_manager = get_employee_email($pm_id);
		$accountant = get_employee_email($a_id);	
		$coordinator = get_employee_email($pc_id);
		$contractor = get_employee_email($contractor_id);
		$director = get_employee_email($dr_id);

		$to = array($submitter, $project_manager, $accountant, $coordinator, $contractor, $director);
		foreach ($to as $t){
			$headers["From"] = "TEST <TEST@gmail.com>";
			$headers["To"] = $t;
			$headers["Subject"] = "TESTING FOR JOB ID $job_id";
		    $text = "TESTING. Please review!";
		    $html = "<html><body>TESTING. Please review!</body></html>";
			$file_path = "./$file";
			$crlf = "\n";
		    $name = "TEST.csv";

		    $smtp_info["host"] = "TEST@gmail.com";
			$smtp_info["port"] = "40";

			$mime = new Mail_mime($crlf);

			$mime->setTXTBody($text);
			$mime->setHTMLBody($html);

			$content_type = "text/csv";
		    $mime->addAttachment($file_path, $content_type, $name);

			$body = $mime->get();
			$hdrs = $mime->headers($headers);

		    $SMTP = Mail::factory('smtp',$smtp_info);
		    $mail = $SMTP->send($t, $hdrs, $body);
			}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.