dezkit Posted March 30, 2008 Share Posted March 30, 2008 whats the code so i can send to multiple people? <?php $to = "[email protected]"; $subject = "dasd"; $body = "sdadas"; if (mail($to, $subject, $body, $headers)) { echo "sadar has been sent."; } else { echo "asddsa has not been sent."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/ Share on other sites More sharing options...
ohdang888 Posted March 30, 2008 Share Posted March 30, 2008 query for the emails stored in a table... while($row = mysql_fetch_assoc($result)){ send email stuff. } EDIT: you shouldn't include multiple emails an email sent on a newsletter.... That would give away everyone's email address to everyone on the list to see. Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504868 Share on other sites More sharing options...
dezkit Posted March 30, 2008 Author Share Posted March 30, 2008 oh, according to the edit you did for your post, what should i do then? Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504871 Share on other sites More sharing options...
dezkit Posted March 30, 2008 Author Share Posted March 30, 2008 admin.php <?php mysql_connect("mysql", "xxx", "xxx") or die(mysql_error()); mysql_select_db("newsletter") or die(mysql_error()); $result = mysql_query("SELECT * FROM users") or die(mysql_error()); echo "<form action='admin2.php' method='post'><textarea name=body1 cols=45 rows=10></textarea><input type=hidden name=to1 value='"; while($row = mysql_fetch_array( $result )) { echo $row['email']; echo ", "; } echo "'><br><input type=submit value=Submit></form>"; ?> admin2.php <?php $to = "$to1"; $subject = "xxxxxxx"; $body = "$body1"; if (mail($to, $subject, $body, $headers)) { echo "Newsletter has been sent."; } else { echo "Newsletter has not been sent."; } ?> correct my code, will ya Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504876 Share on other sites More sharing options...
ohdang888 Posted March 30, 2008 Share Posted March 30, 2008 the code i posted. query to get the all the email addresses stored in a table the WHILE will continue to loop until all results are gone through. so place all the email code in between the while brackets Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504878 Share on other sites More sharing options...
dezkit Posted March 30, 2008 Author Share Posted March 30, 2008 meh, I don't understand still haha, I posted a code above, can you or somebody please correct it. I am not a mysql wiz :'( Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504880 Share on other sites More sharing options...
ohdang888 Posted March 30, 2008 Share Posted March 30, 2008 what are you trying to do, mail a newletter? Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504889 Share on other sites More sharing options...
dezkit Posted March 30, 2008 Author Share Posted March 30, 2008 yeah. Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504891 Share on other sites More sharing options...
dezkit Posted March 30, 2008 Author Share Posted March 30, 2008 index.php <?php $ip = getenv("REMOTE_ADDR") ; ?> <form action="newsletter.php" method="post"> Email: <input type="text" name="email"> <input type="hidden" name="ip" value="<? echo $ip ?>"> </form> newsletter.php <?php $email = $_POST['email']; $ip = $_POST['ip']; // Make a MySQL Connection mysql_connect("mysql", "dezkit", "xxxxxxx") or die(mysql_error()); mysql_select_db("newsletter") or die(mysql_error()); // Insert a row of information into the table "example" mysql_query("INSERT INTO users (email, ip) VALUES('$email', '$ip' ) ") or die(mysql_error()); echo "Thank you for registering for our newsletter!"; ?> admin.php (not password protected page, yet.) <?php mysql_connect("mysql", "dezkit", "xxx") or die(mysql_error()); mysql_select_db("newsletter") or die(mysql_error()); $result = mysql_query("SELECT * FROM users") or die(mysql_error()); echo "<form action='admin2.php' method='post'><textarea name=body1 cols=45 rows=10></textarea><input type=hidden name=to1 value='"; while($row = mysql_fetch_array( $result )) { echo $row['email']; echo ", "; } echo "'><br><input type=submit value=Submit></form>"; ?> admin2.php <?php $to = "$to1"; $subject = "xxxxxxx"; $body = "$body1"; if (mail($to, $subject, $body, $headers)) { echo "Newsletter has been sent."; } else { echo "Newsletter has not been sent."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504897 Share on other sites More sharing options...
dezkit Posted March 30, 2008 Author Share Posted March 30, 2008 I found the problem! i had a space after the "," ! I AM SO HAPPY, THIS IS MY VERY FIRST SCRIPT I DID IN MYSQL! Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504908 Share on other sites More sharing options...
$username Posted March 30, 2008 Share Posted March 30, 2008 You should mark this as solved. Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504921 Share on other sites More sharing options...
dezkit Posted March 30, 2008 Author Share Posted March 30, 2008 i always thought about that, but where is the link to press it? Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504935 Share on other sites More sharing options...
$username Posted March 30, 2008 Share Posted March 30, 2008 Looks like its gone. http://www.phpfreaks.com/forums/index.php/topic,118758.60.html That Sux it was nice to have. Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504945 Share on other sites More sharing options...
redarrow Posted March 30, 2008 Share Posted March 30, 2008 There no headers in your mail code............. also you got to valadate the users input,,,, your also using the users ip that bad programming pratice use a id.... also consider adding a CATCHA so bots dont spam also add a flood protection so users dont post data all the time............ you also need to add mysql_real_escape_string() function to protect database from users.. Quote Link to comment https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504958 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.