Jump to content

php email multiples?


dezkit

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504868
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504876
Share on other sites

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.";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504897
Share on other sites

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..

Link to comment
https://forums.phpfreaks.com/topic/98653-php-email-multiples/#findComment-504958
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.