douxi7219 2017-08-25 18:15
浏览 45

too long

I have a web app which has to send multiple emails. Right now I have the email addresses and passwords stored in a MYSQL database. I have displayed them on a html page and when I click on the link, I am redirecting to a php file that sends the email. I created a BULK-MAIL option where I have to click just one button and there will be multiple redirects from a page called bulk.php to send_mail.php and progressively sends emails for all the items in the database.

After sending like 15 mails or so, I get this error "localhost redirected you too many times."

I have to send 30 emails +/- 1 or 2.

How can I get rid of it ?

Thanks!

bulk.php file:

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 file:

$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();
}

And the button is on the index file.

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

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c