简体   繁体   中英

rotate recipient of my webform submit

I need to add a code to my sendEmail.php bellow which would rotate evenly between two or more recipient. Right now all goes to one recipent "sendto" myemail@gmail.com. So I want to add more myemail-1@gmail.com, myemail-2@gmail.com and so on. This way each will receive fresh leads.

<?php

ob_flush();
session_start();
$_SESSION['username'] = $_POST['username'];
   $_SESSION['email'] = $_POST['email'];
$_SESSION['phone'] = $_POST['phone_1']."- ".$_POST['phone_2']."- ".$_POST['phone_3'];
$_SESSION['liberation'] = $_POST['liberation'];


   $sendto = "myemail@gmail.com";

$email = $_POST['email'];

$username= nl2br($_POST['username']);

$subject = "New lead from my website";


$headers = "From: <form@manysites.com> \r\n";

$headers .= "MIME-Version: 1.0\r\n";

$headers .= "Content-Type: text/html;charset=utf-8 \r\n";

  $msg = "<html><body style='font-family:Arial,sans-serif;'>";

   $msg .= "<p><strong>Name:</strong> ".$_POST['username']."</p>\r\n";

$msg .= "<p><strong>Sent by:</strong> ".$_POST['email']."</p>\r\n";


   $msg .= "<p><strong>Phone No.: </strong> ".$_POST['phone_1']."- ".$_POST['phone_2']."- ".$_POST['phone_3']."</p>\r\n";


   $msg .= "<p><strong> conviction date:</strong> ".$_POST['liberation']."</p>\r\n";

$msg .= "</body></html>";

   @mail($sendto, $subject, $msg, $headers);

header("Location:continue.php");

?> 

You can simply use the comma operator and then send it right away.. like this..

   $sendto = 'myemail1@gmail.com,myemail2@gmail.com,myemail3@gmail.com';
   mail($sendto, $subject, $msg, $headers);

Alternatively, you can use an implode() too..

   $myemails = array('myemail1@gmail.com','myemail2@gmail.com','myemail3@gmail.com');
   $sendto = implode(',',$myemails);
   mail($sendto, $subject, $msg, $headers);

Sending them separately....

$myemails = array('myemail1@gmail.com','myemail2@gmail.com','myemail3@gmail.com')
foreach($myemails as $email)
{
   mail($email, $subject, $msg, $headers);
}

I think the challenge here is that this script runs with no knowledge of what happened on any occasion that it previously ran. So, one option would be to store the information about who received the last lead. This way when the next person fills in your web form, you can retrieve the value of the last recipient and send the current lead to the next recipient in an array of defined recipients (then update the information about who was the last recipient for the next time).

If you don't have access to a database (or file or something else that is a 'permanent' type of storage) to store the value of the last recipient in, you could simply randomize who receives the current lead. The law of averages suggests that over time, the lead distribution should be relatively equal, though in practice this could result in one person getting all of the leads in a given period.

$recipients=array("recipient1@email.com","recipient2@email.com");
$randnum = mt_rand(0,1);
$sendto = $recipients[$randnum];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM