Current location: Hot Scripts Forums » Programming Languages » PHP » Help with Mass Email program


Help with Mass Email program

Reply
  #1 (permalink)  
Old 02-18-05, 10:50 PM
1jetsam 1jetsam is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Help with Mass Email program

I am given 30 minutes to make a program for a friend (he needs it quickly), and I'm having trouble with the code.

Basically he wants to send emails, but he wants only one email field, and each email to be separated by a space.

This is what I have so far:
index.php
PHP Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<
html>
<
head>
    <
title>Mass Emails</title>
</
head>

<
body>
<
form action="send.php" method="post">
Send mass emails:<br>
Send to: <input name="to" type="text" value="" style="width:500"><br>
# of Emails: <input name="number" type="text" value="" style="width:500"><br>
From: <input name="from" type="text" value=""  style="width:500"><br>
Subject: <input name="subject" type="text" value="" style="width:500"><br>
Message: <textarea name="message" rowscols=  style="width:500"></textarea><br>
<
input type="submit" value="Send Emails">
</
form>

</
body>
</
html
send.php
PHP Code:

<?php

$from 
$_POST['from'];
$subject $_POST["subject"];
$message $_POST["message"];
$headers "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: " $from "\r\n";
$c 0;
$emailto $_POST['to'];
for (
$k=0$k<=count($emailto)-1$k++) {
    
$emailto explode(" ",$emailto[$k]);
}
while(
$c<=$_POST['number']) {
$mailsent mail($emailto[$c], $subject$message$headers);
}
?>
The problem is the send page won't load. I think it is in a loophole and can't load the send.php page.

Can someone please help me with this? Any help would be nice, and the faster the better.
__________________
Quate CMS 0.3.3 Released - A simple, fast Content Management System.
Reply With Quote
  #2 (permalink)  
Old 02-19-05, 12:46 AM
wizkid's Avatar
wizkid wizkid is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
You have an infinite loop on your while statement. You dont have anything to increment the value of the variable $c.
Reply With Quote
  #3 (permalink)  
Old 02-19-05, 12:57 AM
1jetsam 1jetsam is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
I actually fixed that part. But there is a problem with the "For" Statement that I have.

index.php
PHP Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


<
html>
<
head>
    <
title>Mass Emails</title>
</
head>

<
body>
<
form action="send.php" method="post">
Send mass emails:<br>
Send to: <input name="to" type="text" value="" style="width:500"><br>
# of Emails: <input name="number" type="text" value="" style="width:500"><br>
From: <input name="from" type="text" value=""  style="width:500"><br>
Subject: <input name="subject" type="text" value="" style="width:500"><br>
Message: <textarea name="message" rowscols=  style="width:500"></textarea><br>
<
input type="submit" value="Send Emails">
</
form>

</
body>
</
html
send.php
PHP Code:

<?php

$from 
$_POST['from'];
$subject $_POST["subject"];
$message $_POST["message"];
$headers "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: " $from "\r\n";
$c 1;
$emailto $_POST['to'];
for (
$k=0$k<=count($emailto)-1$k++) {
    
$emailto explode(" ",$emailto[$k]);
}
while(
$c<=$_POST['number']) {
$mailsent mail($emailto[$c], $subject$message$headers);
echo 
$emailto[$c]. "<br>";
if (
$mailsent) {
  echo 
"Sent.<br>";
} else {
  echo 
"Failed.<br>";
}
$c++;
}
echo 
"<br>Done!";
?>
__________________
Quate CMS 0.3.3 Released - A simple, fast Content Management System.
Reply With Quote
  #4 (permalink)  
Old 02-19-05, 02:11 AM
wizkid's Avatar
wizkid wizkid is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
i dont have the time to try this but i guess this would solve it:

PHP Code:

$c 0;

//email add are separated by single blank space
$emailto explode(" ",$_POST['to']);
while(
$c<count($emailto)) {
  
mail($emailto[$c], $subject$message$headers); 
  
$c++; 

Reply With Quote
  #5 (permalink)  
Old 02-19-05, 12:04 PM
1jetsam 1jetsam is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
I tried that and it didn't work.
Thanks though.
__________________
Quate CMS 0.3.3 Released - A simple, fast Content Management System.
Reply With Quote
  #6 (permalink)  
Old 02-19-05, 12:48 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
why would you do 2 loops ?
one is enough!
PHP Code:

<?php

$from 
$_POST['from'];
$subject $_POST["subject"];
$message $_POST["message"];
$headers "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: " $from "\r\n";

$emailto explode(' 'trim($_POST['to']) );

for (
$k=0$k<count($emailto); $k++) {

    
$mailsent mail($emailto[$k], $subject$message$headers);

    echo 
$emailto[$k]. '<br>';

    if (
$mailsent)
       echo 
'Sent.<br>';
    else
        echo 
'Failed.<br>';
}

echo 
"<br>Done!";
?>
try this one instead!
I assumed that $_POST['to'] contains the email addresses with space seperating each of them, made the explode() and then mailed each one..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #7 (permalink)  
Old 02-19-05, 02:23 PM
1jetsam 1jetsam is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks! It works great!
__________________
Quate CMS 0.3.3 Released - A simple, fast Content Management System.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Trial of Email Newsletter Campaign findyourhope General Advertisements 0 01-05-05 08:58 PM
need help to create a attachment on my email frankkk PHP 1 10-25-04 02:10 PM
Running a Script from an Email newhorizonz Perl 6 09-24-04 06:36 PM
Mass Emailing to Individual Emaill Address inky ASP 0 08-24-04 02:07 AM
Please assist. My public email request form is under siege! AshleyQuick Perl 1 05-10-04 02:54 AM


All times are GMT -5. The time now is 05:32 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.