Script trimitere email la mai multe adrese

Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
Valentin89
Mesaje: 4

Script trimitere email la mai multe adrese

Buna seara, am un script in php care doresc sa-l modific astfel incat sa trimita la mesaje la mai multe adrese de email, indiferent ca intra in spam sau inbox...
Problema lui este ca trimite doar la o singura adresa de email, daca ma puteti ajuta sa-l modific sa trimita la mai multi ar fi perfect...eventual sa existe un fisier email.txt in care sa introduci lista de emailuri la care sa trimita scriptu.

Asta e codul meu.
Multumesc anticipat,
Cu stima Valentin

Cod: Selectaţi tot

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mass Mailer</title>
<!-- TinyMCE -->
<script type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
    tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

        // Theme options
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Example content CSS (should be your site CSS)
        content_css : "css/content.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "lists/template_list.js",
        external_link_list_url : "lists/link_list.js",
        external_image_list_url : "lists/image_list.js",
        media_external_list_url : "lists/media_list.js",

        // Replace values for the template plugin
        template_replace_values : {
            username : "Some User",
            staffid : "991234"
        }
    });
</script>
<!-- /TinyMCE -->
<style type="text/css">
<!--
body {
    background-image: url(images/bg.gif);
    text-align: left;
    font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
    font-size: 18px;
    color: #060;
}
}
.head p {
    font-size: 48px;
    color: #06F;
}
.footer {
    text-align: left;
    color: #390;
    font-weight: bold;
}
-->
</style></head>
<body >
<div class="head">
  <p><img src= "images/logo.png"/></p>
</div>
<?php
 
/**
 * @author Sonu Joshi
 * @copyright 2010
 */
function check_email_address($id)
{
    // First, we check that there's one @ symbol,
    // and that the lengths are right.
    if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $id))
    {
        // Email invalid because wrong number of characters
        // in one section or wrong number of @ symbols.
        return false;
    }
    // Split it into sections to make life easier
    $id_array = explode("@", $id);
    $local_array = explode(".", $id_array[0]);
    for ($i = 0; $i < sizeof($local_array); $i++)
    {
        if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
?'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i]))
        {
            return false;
        }
    }
    // Check if domain is IP. If not,
    // it should be valid domain name
    if (!ereg("^\[?[0-9\.]+\]?$", $id_array[1]))
    {
        $domain_array = explode(".", $id_array[1]);
        if (sizeof($domain_array) < 2)
        {
            return false; // Not enough parts to domain
        }
        for ($i = 0; $i < sizeof($domain_array); $i++)
        {
            if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
?([A-Za-z0-9]+))$", $domain_array[$i]))
            {
                return false;
            }
        }
    }
    return true;
}
if (!$_POST['list'])
{
 
?>
<div class="from">
<form action="index.php" method="post">
    <label>From:
<input type="text" name="from" id="from" />
    </label>
    <div class="subject">
      <p>Subject<span class="from">:</span><span class="from">
        <label>
          <input type="text" name="subject" id="subject" />
        </label>
      </span></p>
</div>
  <div class="list">
    <p>E-Mail List:<span class="from">
      <label>
        <input type="text" name="list" id="list" />
      </label>
    </span></p>
</div>
  <div class="msg">
    <p>Message Body:</p>
    <p>
  <label>
    <textarea name="body" id="body" rows="15" cols="80" style="width: 80%"></textarea>
  </label>
    </p>
  </div>
  <div class="send">
  <label>
    <input type="submit" name="submit" id="submit" value="Send" />
  </label>
</form>
<div class="credits"></div>
</div>
<?
 
} elseif ($_POST['list'] && $_POST['subject'] && $_POST['body'] && $_POST['from'])
{
    $list = $_POST['list'];
    $subject = $_POST['subject'];
    $message .= $_POST['body'];
    $from = $_POST['from'];
    $headers = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n"; 
    
    $list = explode(",", $list);
    if (check_email_address($from))
    {
        foreach ($list as $email)
        {
 
            if (check_email_address($email))
            {
                if (mail($email, $subject, $message, $headers))
                {
                    echo "Email sent to $email. <br />";
 
                } else
                {
                    echo "<span style='color:red'>The mail could no be sent for some unexpected reason.</span>";
                }
 
            } elseif (!check_email_address($email))
            {
                echo "<span style='color:red'>$email is not valid e-mail ID</span> <br />";
            }
            sleep(0.5);
 
        }
    } elseif (!check_email_address($from))
    {
        echo "<span style='color:red'>Please enter an appropriate e-mail id.</span>";
    }
 
}
 
?>
<br /><br /><br />
</body>
</html>

MarPlo Mesaje: 4343
Salut
Acel cod e asa de vechi /depasit, functioneaza doar pe versiuni php vechi (de acum 6-7 ani). Pe veersiunile mai noi iti va da eroare: "Function ereg() is deprecated".
Daca ruleaza pe o versiun\e php veche, ar trebui sa trimita email-ul la toate adresele adaugate in casuta de la "E-Mail List".
In acea caseta de formular trebuie sa adaugi lista de adrese separate prin virgula. Exemplu: "adr1@domain.net,adr2@domain.net,adr3@domain.com".

Subiecte similare