Note that there are some explanatory texts on larger screens.

plurals
  1. POsending multiple emails with for loop in phpmailer
    primarykey
    data
    text
    <p>I want to send multiple emails with diferent content. For that the user need to select checkbox and click a button to send all emails checked.</p> <p>For that I have a table just to show the content from database.</p> <pre><code> select nomeUser,email,nomeVoucher,categoria,preco,confirmacao,fileName,filePDF from historico Where confirmacao = 'a confirmar' LIMIT $start, $per_page"; $stmt = $mybd-&gt;prepare($query); $stmt-&gt;execute(); $stmt-&gt;bind_result($nomeUser,$email,$nomeVoucher,$categoria,$preco,$confirmacao,$file2,$filePDF); while($stmt-&gt;fetch()){ ?&gt; &lt;tbody&gt; &lt;tr&gt;&lt;td&gt;&lt;?php echo $nomeUser ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $email ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $nomeVoucher ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $categoria ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $preco ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $confirmacao ?&gt;&lt;/td&gt; &lt;?php $current = file_get_contents($file2,$filePDF); ?&gt; &lt;td style='display:none;'&gt;&lt;?php echo $current ?&gt;&lt;/td&gt; &lt;td style='display:none;'&gt;&lt;?php echo $file2 ?&gt;&lt;/td&gt; &lt;td&gt;&lt;INPUT TYPE='checkbox' NAME='mail[]' VALUE='1'&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;?php }$stmt-&gt;close(); </code></pre> <p>The code to send it's that:</p> <pre><code>if(isset($_POST['enviar'])){ $mails = $_POST['mail']; if(count($mails) &gt; 0){ for($i=0;$i&lt;count($mails);$i++){ $fromname[$i] = "Compra do Voucher"; $from[$i] = "jonathan@tribanet.com"; $subject[$i] = "Compra do Voucher"; $message = "O seu pagamento foi verificado com sucesso!" . "\r\n" . "Por favor, verifica se o voucher pedido é o sucedido: " . "\r\n" . "Categoria: $categoria[$i] \r\n" . "Nome do Voucher: $nomeVoucher[$i] \r\n" . "Preço: $preco[$i] € \r\n" . "O seu voucher está disponível aqui $nomeVoucher[$i] \r\r\n" . "Equipa do Voucher \r\n"; $new_array=array($email[$i]); $newstring=implode(",",$new_array); $mail = new PHPMailer(); $mail-&gt;isSMTP(); $mail-&gt;SMTPAuth = true; $mail-&gt;Host = "smtp.sapo.pt"; $mail-&gt;Username = "jonitopsg@sapo.pt"; $mail-&gt;Password = "200886"; $mail-&gt;Port = 25; $mail-&gt;Sender = "$from[$i]"; $mail-&gt;FromName = "$fromname[$i]"; $mail-&gt;Subject = "$subject[$i]"; $mail-&gt;Body = "$message"; $mail-&gt;CharSet="utf-8"; $mail-&gt;AddStringAttachment($current[$i],$file2[$i]); $mail-&gt;AddAddress($newstring,$nomeUser[$i]); if ($mail-&gt;send()){ return true; }else return $mail-&gt;ErrorInfo; $mail-&gt;ClearAddresses(); $mail-&gt;ClearAttachments(); } } } </code></pre> <p>It diplays th error: "Invalid Address: You must provide at least one recipient email address." What I'm doing wrong? Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload