在批量电子邮件时,localhost会将您重定向到太多次

时间:2017-08-25 18:15:49

标签: php mysql email redirect bulk

我有一个必须发送多封电子邮件的网络应用。现在我将电子邮件地址和密码存储在MYSQL数据库中。我已经在html页面上显示它们,当我点击链接时,我将重定向到发送电子邮件的php文件。 我创建了一个 BULK-MAIL 选项,我只需点击一个按钮,就会有一个名为bulk.php的页面中有多个重定向到send_mail.php并逐步发送电子邮件对于数据库中的所有项目。

发送大约15封邮件之后,我收到此错误" localhost重定向了你太多次。"

我必须发送30封电子邮件+/- 1或2。

我该怎样摆脱它?

谢谢!

bulk.php文件:

require('connections/conexiune.php');

$sql = "SELECT id, nume, email, parola, temp_trimis FROM firme ORDER BY nume DESC";
$res = $conn->query($sql);

$i=0;

if ($res->num_rows > 0) {
    // output data of each row
    while($firma = $res->fetch_assoc()){
        if($firma["temp_trimis"]==0){
            header("Location: send_email.php?nume=".$firma['nume']."&id=".$firma['id']."&email=".$firma['email']."&parola=".$firma['parola']."&blk=1");
        }else{
            $i++;
        }
    }
    $conn->close();
}
if($i==30) header("Location: index.php");

send_email.php文件:

$luni = array('Ianuarie', 'Februarie', 'Martie', 'Aprilie', 'Mai', 'Iunie', 'Iulie', 'August', 'Septembrie', 'Octombrie', 'Noiembrie', 'Decembrie');
$luna = date('m');
$luna = strtoupper($luni[(int)$luna-2]) . " " . date('Y');

require('connections/conexiune.php');
require("libs/phpmailer/PHPMailerAutoload.php");

//preluarea de date
if(isset($_GET['nume'],$_GET['email'],$_GET['id'],$_GET['parola'])){
    $fields=[
        'nume_firma' => $_GET['nume'],
        'email' => $_GET['email'],
        'id' => $_GET['id'],
        'parola' => $_GET['parola'],
    ];
    if(isset($_GET['blk'])){
        $blk=$_GET['blk'];
    }else{
        $blk=0;
    }
}


//Atasament
foreach (glob("export/*") as $filename) {
    $k = strpos($filename, $fields['id']);
    if($k == TRUE){
        $att=$filename;
    }
}

//determinarea hostului(gmail sau yahoo) in functie de email    
$detHost=strpos($fields['email'],'gmail');

if($detHost == TRUE){
    $host="smtp.gmail.com";
}else{
    $host="smtp.mail.yahoo.com";
}

class Mailer extends PHPMailer {
    public function copyToFolder() {
        $message = $this->MIMEHeader . $this->MIMEBody;
        $imapStream = imap_open("{imap.mail.yahoo.com:993/imap/ssl}Sent", $this->Username , $this->Password);
        imap_append($imapStream, "{imap.mail.yahoo.com:993/imap/ssl}Sent", $message, "\\Seen");
        imap_close($imapStream);
    }
}


$m = new Mailer();


        $m -> isSMTP();
        $m -> SMTPAuth = true;

        $m -> Host = ''.$host.'';
        $m -> From = ''.$fields['email'].'';
        $m -> FromName = ''.$fields['nume_firma'].'';
        $m -> Username = ''.$fields['email'].'';
        $m -> Password = ''.$fields['parola'].'';
        $m -> SMTPSecure = 'ssl';
        $m -> Port = 465;
        $m->SMTPOptions = array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        );
        $m ->isHTML();
        $m -> Subject = 'Raportare sumal luna '.$luna.' pentru '.$fields['nume_firma'].'';
        $m -> Body = 'Buna ziua!<p>
                        Va trimit in atasament raportarea sumal pentru luna '.$luna.' - '.$fields['nume_firma'];
        $m -> FromName = 'Aplicatie Raportari Sumal';
        $m->addAddress('raportariemapp@gmail.com');
        //$m->addAddress('sumal.mures@gmail.com');
        $m->addAttachment(''.$att.'');
        //$m->SMTPDebug = 4;

if(!$m->Send())
{

   echo "Mesajul nu a fost trimis ! <p>";
   echo "Mailer Error: " . $m->ErrorInfo;

   exit;
}else{
    if($blk==0){
        header("Location: index.php");
    }else{
        header("Location: bulk.php");
    }

    $sql = "UPDATE firme SET temp_trimis = 1 WHERE id = ".$fields['id']."";
    $res = $conn->query($sql);

    if($detHost==FALSE)
        $m->copyToFolder();
}

按钮位于索引文件上。

<button type="button" class="btn" onclick="location.href='bulk.php'">BULK-MAIL</button>

0 个答案:

没有答案