Note that there are some explanatory texts on larger screens.

plurals
  1. POtwo foreach loops combined for email sending
    primarykey
    data
    text
    <p>I am trying to take a two text areas with multiple emails, one with the "from" emails, and one with the "to" emails. Combine the emails line by line and send emails out accordingly.</p> <p>Ex:</p> <p>"To" list: </p> <pre><code> mike@gmail.com nick@hotmail.com adam@yahoo.com </code></pre> <p>"From" list: </p> <pre><code> ashley@gmail.com brittney@yahoo.com racheal@hotmail.com </code></pre> <p>I want a email sent to:</p> <pre><code> mike@gmail.com from ashley@gmail.com nick@hotmail.com from brittney@yahoo.com adam@yahoo.com from racheal@hotmail.com </code></pre> <p>Any help would be greatly appreciated. Thanks in advanced.</p> <p>Below is the script I got so far, It sends to multiple emails from one email.</p> <pre><code> &lt;?php if (isset($_POST['submit'])) { // Execute this code if the submit button is pressed. $raw_email_account = $_POST['email_from']; $email = $_POST['email_to']; $sent = ""; $invalid = ""; //Separating each line to be read by foreach $list = explode("\n",$email); //Rendering the separeted data from each line foreach($list AS $data) { //Separating each line to be read by foreach $item = explode(":",$data); $mail_body = '&lt;html&gt;&lt;body&gt;email here&lt;/body&gt;&lt;/html&gt;'; $subject = "subject here"; $headers = "From:".$raw_email_account."\r\n"; $headers .= "Content-type: text/html\r\n"; $to = $item[0]; $mail_result = mail($to, $subject, $mail_body, $headers); if ($mail_result) { $valid++; } else { // write into an error log if the mail function fails $invalid++; } } } ?&gt; &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="email_sender.php" method="POST"&gt; &lt;div align="center"&gt;From Email Accounts: &lt;textarea name="email_from" cols="100" rows="60"&gt;&lt;/textarea&gt;&lt;/div&gt;&lt;br /&gt; &lt;div align="center"&gt;To Email Accounts: &lt;textarea name="email_to" cols="100" rows="60"&gt; &lt;/textarea&gt;&lt;/div&gt;&lt;br /&gt; &lt;div align="center"&gt;&lt;input type="submit" name="submit"&gt;&lt;/div&gt; &lt;br&gt; Valids: &lt;?php echo $valid;?&gt; &lt;br&gt; Invalids: &lt;?php echo $invalid;?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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