Jump to content

php email multiples?


dezkit

Recommended Posts

whats the code so i can send to multiple people?

 

<?php
$to = "das@sda.com";
$subject = "dasd";
$body = "sdadas";

if (mail($to, $subject, $body, $headers)) {
  echo "sadar has been sent.";
} else {
  echo "asddsa has not been sent.";
}
?>

Link to comment
Share on other sites

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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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