0

i want to send email to multiple destinataries but in destinatary shows only the email and not the others mails

for example :

instead of:

mail('[email protected],[email protected],[email protected]', $asunto, $html,$header);

in mail box: http://prntscr.com/6g4zkz

could be in mail box: http://prntscr.com/6g4zz1

but sending the 3 emails ?

Edit:

i solved like this:

while ($resulta = $dati->fetch_array()) {
            $email = $resulta['email'];
            mail($email, $asunto, $html,$header);
        }

the only problem is i dont know how to return true or false:

public function feed_mail($id){
        $mysqli = $this->connection();
        $data = $mysqli->query("SELECT * FROM feed");
        $dati = $mysqli->query("SELECT * FROM feed");
        $dato = $mysqli->query("SELECT * FROM blog where id='$id'");
        $resultado = $dato->fetch_array();
        $title = $resultado['title'];
        $date = $resultado['date'];
        $autor= $resultado['author'];
        $body = base64_decode($resultado['body']);
        $asunto = 'Ortoflex - '.$title;
        while ($resultados = $data->fetch_array()) {
        $html = '<div style="width:80%;padding: 100px; background: #E4EDF6;border:10px solid #000000;">';
                        $html .= '<h1><b>'.$title.'</b></h1>';
                        $html .= '<br>';
                        $html .= $date;
                        $html .= '<hr>';
                        $html .= '<br>';
                        $html .= $body;
                        $html .= '<hr><br>';
                        //while ($resultados = $data->fetch_array()) {
                        $html .= '<a href="'.$this->url.'unsuscribe?hash='.$resultados['hash'].'">Anular Suscripci&oacute;n</a>';   
                        }
                        $header .="MIME-Version: 1.0\n"; 
        $header .= "Content-type: text/html; charset=iso-8859-1\n"; 
        $header .="From: Ortoflex.mx<[email protected]>\n";
        $header .="Return-path: [email protected]\n";
        $header .="X-Mailer: PHP/". phpversion()."\n";
        //$header .= "Bcc: ".$item."\r\n";
        $to = '[email protected]';       
while ($resulta = $dati->fetch_array()) {
            $email = $resulta['email'];
            mail($email, $asunto, $html,$header);
        }

            return true;

    }
Emilo
  • 35
  • 7

3 Answers3

1

send the mail by placing ur destinataries in BCC. That what your recipient wouldn't be able to see others email address. Following is the sample code

Set you email field to null and

$to=array();
$headers .= 'From: Jack.com <[email protected]' . "\r\n";
$headers .= 'BCC: '. implode(",", $to) . "\r\n";


mail(null, $title, $content, $headers);
Ravikiran butti
  • 1,668
  • 2
  • 11
  • 18
0

Use This :-

$headers .= 'From: SmsGratisan.com <[email protected]' . "\r\n";
$headers .= 'BCC: '. implode(",", $to) . "\r\n";


mail(null, $title, $content, $headers)
0

User BCC in the header

$to=array(); 
$headers .= 'From: Jack.com <[email protected]' . "\r\n";
$headers .= 'BCC: '. implode(",", $to) . "\r\n"; 
if(mail(null, $title, $content, $headers))
  return true; 
else 
  return false;

or

convert the string to array and iterate over it

$ids='[email protected],[email protected],[email protected]'
$emails[]=explode(" ", $ids);
$errors[]="";
for($i=0;$i<count($emails);$i++)
{
  if(!mail($emails[$i], $asunto, $html,$header)){
      $errors[]="Email function didn't work for".$emails[$i];
   }

}

Another way if you want to know the exact error (by using try and catch)

for($i=0;$i<count($emails);$i++)
{
  try{
     mail($emails[$i], $asunto, $html,$header);
     }
    catch(Exception $exception){
     $errors[]=$exception->getMessage(). " <- exception for email   ".$emails[$i];
    }   
}
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78