how to get all images with foreach

0

How do I get all the img with the foreach and send for email , I put my function to send the email inside the loop but it will not send me only the first one and if I put the function out of the loop he sends me the last one could help me?

code

if(!empty($_POST)){
        foreach($_POST['ck'] as $ck){
            $msg = "<img src=\"http://www.site.com.br/images/$ck\"width=\"100px\" height=\"70px\"><br>";

                // manda e-mail usuario
                $mail = new PHPMailer();
                $mail-> IsSMTP();
                $mail->CharSet = "UTF-8";
                $mail->SMTPAuth = true;
                $mail->SMTPSecure = 'tls';
                $mail->Port = 587;
                $mail->Host = "smtp.zoho.com";
                $mail->Username = "[email protected]";
                $mail->Password = "senha";
                $mail->SetFrom("[email protected]", "usuario");

                $mail->AddAddress("[email protected]", "usuario");
                $mail->Subject = "assunto";
                $mail->msgHTML($msg);

                if($mail->send()){
                    echo "enviado com sucesso";
                    exit();
                }else{
                    echo "Erro ao enviar o email".$mail->ErrorInfo;
                }
            }       

    }
    
asked by anonymous 26.10.2016 / 21:09

1 answer

0

Leave out everything that does not vary, such as creating the PHPMailer object and sending it from the email. Uses the Body property to format / manipulate / assign the email message.

if(!empty($_POST)){

    $mail = new PHPMailer();
    $mail-> IsSMTP();
    $mail->CharSet = "UTF-8";
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = 'tls';
    $mail->Port = 587;
    $mail->Host = "smtp.zoho.com";
    $mail->Username = "[email protected]";
    $mail->Password = "senha";
    $mail->SetFrom("[email protected]", "usuario");
    $mail->Subject = "assunto";
    $mail->AddAddress("[email protected]", "usuario");

    foreach($_POST['ck'] as $ck){
        $msg = "<img src=\"http://www.site.com.br/images/$ck\"width=\"100px\" height=\"70px\"><br>";
        $mail->Body .= $msg;
    }

    if($mail->send()){
        echo "enviado com sucesso";
        exit();
    }else{
        echo "Erro ao enviar o email".$mail->ErrorInfo;
    }           
}       
    
26.10.2016 / 21:18