Trimitere Mass Mail din PHP

Aici vorbim despre CSS, PHP, C++, MySql, Javascript, Java & jQuery.
Post Reply
JustMike
Membru
Posts: 22
Joined: 19 Nov 2014, 21:26
Nume Real: Mihai
Nivel cunoştinţe IT: 10

20 Nov 2014, 14:22

Salutari, in acest articol am sa va prezint un script PHP de trimis mass mail, dupa cum spune si titlul...

Puteti trimite la mai multe adrese de email in acelasi timp (separate de virgula (,) ) si puteti seta prioritatea mailurilor.

!Atentie: Pentru ca acest script sa functioneze trebuie sa aveti functia mail() a serverului web activata.

Code: Select all

<?php

if( $_SERVER['REQUEST_METHOD'] === 'POST' ){
	$emails = explode(',', $_POST['mailuri']);
	foreach( $emails as $email ){
        $headers = "MIME-Version: 1.0";
        $headers .= "Content-type: text/plain; charset=iso-8859-1";
        $headers .= "From: " . $_POST["numele_tau"] . " <" . $_POST["mail_tau"] . ">";
        $headers .= "Bcc: " . $email;
        $headers .= "Reply-To: <" . $_POST["replyto"] . ">";
        $headers .= "Subject: " . $_POST["subject"];
        if($_POST["epriority"]==1){
            $headers .= "X-Priority: 1 (Highest)";
            $headers .= "X-MSMail-Priority: High";
            $headers .= "Importance: High";
        }elseif($_POST["epriority"]==3){
            $headers .= "X-Priority: 5 (Lowest)";
            $headers .= "X-MSMail-Priority: Low";
            $headers .= "Importance: Low";
        }		
        $headers .= "X-Mailer: PHP/".phpversion();
        mail($email, $_POST["subject"], $_POST["text_mail"], $headers);		
	}
	header('Location: mail.php');
}

?>
<form action='' method="POST">
<table>
<tr>
<td>
Emails :</br><textarea name="mailuri" cols="50" rows="15" maxlength="10000" wrap="soft"></textarea></td><td>
<table><tr><td>
    Your Email : </br><input type="text" name="mail_tau" size="40"></td></tr><tr><td>
    Your Name : </br><input type="text" name="numele_tau" size="40"></td></tr><tr><td>
    Reply-To : </br><input type="text" name="replyto" size="40"></td></tr><tr><td>
    Subject : </br><input type="text" name="subject" size="40"></td></tr><tr><td>
    Email Priority : </br><select name="epriority">
        <option selected="" value="">- Please Choose -</option>
        <option value="1">High</option>
        <option value="2">Normal</option>
        <option value="3">Low</option>
    </select>
</td></tr></table></td></tr></table></td></tr><tr><td>
Your Text : </br><textarea name="text_mail" cols="86" rows="15" maxlength="10000" wrap="soft"></textarea></td>
</td></tr></table></br>
<input type="Submit" value="Send Emails">
</form>
Codul se gaseste si pe PasteBin-ul meu: http://pastebin.com/snU3uTKf
Best Movies Community : Recomanda-Film!
User avatar
tataieee
Administrator
Posts: 3839
Joined: 17 Sep 2014, 17:52
Nume Real: Alexandru Costin
Nivel cunoştinţe IT: 10
Location: Giurgiu; România
Contact:

20 Nov 2014, 14:30

Folositor, ce interval de timp este între expedierea email-urilor?
*Email: w.tataieee@gmail.com
*PayPal: w.tataieee@yahoo.com
JustMike
Membru
Posts: 22
Joined: 19 Nov 2014, 21:26
Nume Real: Mihai
Nivel cunoştinţe IT: 10

20 Nov 2014, 14:35

Nu-i nici-un delay in codul de mai sus, dar daca se doreste neaparat se poate pune ceva de genul acesta in foreach:

Code: Select all

        sleep(5);
iar 5 este numarul de secunde ale asa zis-ului delay.
Best Movies Community : Recomanda-Film!
User avatar
007
Membru
Posts: 3
Joined: 22 Oct 2014, 21:21
Nume Real: cristian
Nivel cunoştinţe IT: 10

03 Jan 2015, 21:50

unde vine pus codul asta sleep(5); sal citesca???
JustMike
Membru
Posts: 22
Joined: 19 Nov 2014, 21:26
Nume Real: Mihai
Nivel cunoştinţe IT: 10

05 Jan 2015, 19:04

sleep(x)-ul se pune in foreach ca pentru fiecare email trimis sa faca o pauza de x secunde.Codul ar trebuii sa arate ceva de genul asta:

Code: Select all

<?php

if( $_SERVER['REQUEST_METHOD'] === 'POST' ){
   $emails = explode(',', $_POST['mailuri']);
   foreach( $emails as $email ){
        $headers = "MIME-Version: 1.0";
        $headers .= "Content-type: text/plain; charset=iso-8859-1";
        $headers .= "From: " . $_POST["numele_tau"] . " <" . $_POST["mail_tau"] . ">";
        $headers .= "Bcc: " . $email;
        $headers .= "Reply-To: <" . $_POST["replyto"] . ">";
        $headers .= "Subject: " . $_POST["subject"];
        if($_POST["epriority"]==1){
            $headers .= "X-Priority: 1 (Highest)";
            $headers .= "X-MSMail-Priority: High";
            $headers .= "Importance: High";
        }elseif($_POST["epriority"]==3){
            $headers .= "X-Priority: 5 (Lowest)";
            $headers .= "X-MSMail-Priority: Low";
            $headers .= "Importance: Low";
        }      
        $headers .= "X-Mailer: PHP/".phpversion();
        mail($email, $_POST["subject"], $_POST["text_mail"], $headers);      
        sleep(5);
   }
   header('Location: mail.php');
}

?>
<form action='' method="POST">
<table>
<tr>
<td>
Emails :</br><textarea name="mailuri" cols="50" rows="15" maxlength="10000" wrap="soft"></textarea></td><td>
<table><tr><td>
    Your Email : </br><input type="text" name="mail_tau" size="40"></td></tr><tr><td>
    Your Name : </br><input type="text" name="numele_tau" size="40"></td></tr><tr><td>
    Reply-To : </br><input type="text" name="replyto" size="40"></td></tr><tr><td>
    Subject : </br><input type="text" name="subject" size="40"></td></tr><tr><td>
    Email Priority : </br><select name="epriority">
        <option selected="" value="">- Please Choose -</option>
        <option value="1">High</option>
        <option value="2">Normal</option>
        <option value="3">Low</option>
    </select>
</td></tr></table></td></tr></table></td></tr><tr><td>
Your Text : </br><textarea name="text_mail" cols="86" rows="15" maxlength="10000" wrap="soft"></textarea></td>
</td></tr></table></br>
<input type="Submit" value="Send Emails">
</form>
Aici se gaseste documentatia functiei sleep() in PHP: https://php.net/manual/ro/function.sleep.php
Best Movies Community : Recomanda-Film!
Post Reply

Return to “CSS, PHP, C++, MySql, Javascript, Java & jQuery”