View Full Version : More Php help Please
midwesthosting
April 26th, 2007, 03:01
Im Trying too get this Mailing list Too work so i dont have to Add emails One by One
Bellow is the code for the Single Add,Work's But can SomeOne help me make this Multi Please
<?php
session_start();
include "connect.php";
?>
<link rel="stylesheet" href="style.css" type="text/css">
<center><table border='0'><tr><td valign='top' width=30%>
<?php
if(isset($_SESSION['mailadmin']))
{
include "left.php";
print "</td>";
print "<td valign='top' width=70%>";
print "<table class='maintable'><tr class='headline'><td><center>Add Address<center></td></tr>";
print "<tr class='mainrow'><td>";
$mailid=$_GET['ID'];
if(isset($_POST['submit']))
{
$email=$_POST['email'];
$getaddress="SELECT * from m_list where address='$email'";
$getaddress2=mysql_query($getaddress) or die("Could not get address");
$getaddress3=mysql_fetch_array($getaddress2);
if(strlen($getaddress3['address'])>0)
{
print "That email is already subscribed.";
}
else
{
$rseed=date("U")%1000000;
$value=$_POST['validated'];
srand($rseed);
$thekey=md5(rand(10000,10000000));
$email=$_POST['email'];
$newaddress="INSERT into m_list (address,validated,mailkey) values('$email','$value','$thekey')";
$newaddress2=mysql_query($newaddress) or die("Could not query");
mail("$email",$confirmthing,"To complete your subscription please click on the following link: $yourfilepath/confirm.php?email=$email&thekey=$thekey","From: $yourmail");
print "A confirmation link has been sent to your email address.";
}
}
else
{
print "When you add an e-mail to your list, a confirmation will be sent to their email.<br>";
print "<form action='addaddress.php' method='post'>";
print "Email to add:<br>";
print "<input type='text' name='email' size='30'><br>";
print "Auto Validate <Br>";
print "<input name='value' type='checkbox' value='1' checked />
<br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
print "</td></tr></table>";
}
?>
krakjoe
April 26th, 2007, 04:39
Multi in what sense exactly ? ?
Can I see the form too
webadpro
April 26th, 2007, 07:02
Joe, he means having a multi email sender(different email addresses).
DarkBlood
April 26th, 2007, 12:37
You can use less variables by the way. Change $getaddress2 to $getaddress. Your variables in the string need curly brackets around them.
Right now you have it set up to only accept ONE E-Mail and to GET One-E-Mail. So it's a no brainer why it won't work. The problem is how to make it to accept more than one. I don't know how I would do that working with this, but the for conditional statement (http://us2.php.net/manual/en/control-structures.for.php) could help you out.
Make sure your counter goes up until $email_array.length
krakjoe
April 26th, 2007, 12:51
.length doesn't exist in php
@op, please explain what you mean by multi, do you mean you want to be able to add more than one address at a time ?
DarkBlood
April 26th, 2007, 13:36
.length is used to determine the size of the array, I've used it several times for a for loop. There's also sizeof and count functions if you don't want to risk using .length.
krakjoe
April 26th, 2007, 13:45
.length DOESN'T EXIST IN PHP SO NO YOU HAVEN'T
stuffradio
April 26th, 2007, 15:11
looks like he wants to be able to add more than one address at a time, the form is here:
print "When you add an e-mail to your list, a confirmation will be sent to their email.<br>";
print "<form action='addaddress.php' method='post'>";
print "Email to add:<br>";
print "<input type='text' name='email' size='30'><br>";
print "Auto Validate <Br>";
print "<input name='value' type='checkbox' value='1' checked />
<br>";
print "<input type='submit' name='submit' value='submit'></form>";
krakjoe
April 26th, 2007, 15:43
<?php
session_start();
include "connect.php";
function addEmail( $email, $key )
{
return mysql_query( sprintf( 'INSERT INTO `m_list` ( address, validated, mailkey ) VALUES(\'%s\', \'%s\', \'%s\')', $email, 1, $key ) );
}
function userConfirm( $email, $key )
{
global $yourfilepath ;
return mail( $email,
'Confirm Email Address',
"To complete your subscription please click on the following link: ".
"<a href=\"$yourfilepath/confirm.php?email=$email&thekey=$key\">".
"$yourfilepath/confirm.php?email=$email&thekey=$key</a>",
"From: $email <$email>\r\n".
"Content-type: text/html\r\n"
);
}
function emailExists( $email )
{
return @mysql_num_rows( mysql_query("SELECT address FROM `m_list` WHERE address = '$email' LIMIT 1") );
}
function message( $message, $color = "red" )
{
return sprintf( '<font color=\"%s\"><b>%s</b><br />', $color, $message );
}
?>
<link rel="stylesheet" href="style.css" type="text/css">
<center><table border='0'><tr><td valign='top' width=30%>
<?php
if( isset($_SESSION['mailadmin']) )
{
include "left.php";
print "</td>";
print "<td valign='top' width=70%>";
print "<table class='maintable'><tr class='headline'><td><center>Add Address<center></td></tr>";
print "<tr class='mainrow'><td>";
$mailid=$_GET['ID'];
if( $_POST )
{
if( trim( $_POST['emails'] ) != "" )
{
$sent = 0;
foreach( split("\n", stripslashes(trim($_POST['emails']))) as $indexed => $email )
{
if( $email != "" ):
$random = md5( mt_rand( 10000, 1000000 ) );
if( emailExists( $email ) )
{
echo message( "$email exists in the database, skipping" );
}
elseif( !addEmail( $email, $random ) )
{
echo message( "$email cannot be added, bailing" );
exit;
}
elseif( !userConfirm( $email, $random ) )
{
echo message( "Cannot email $email, bailing" );
exit;
}
else
{
echo message( "$email added and confirmation email sent", 'blue' );
}
endif;
}
echo message( "$sent users added with success", 'blue' );
}
else
{
echo message( 'ENTER EMAILS DUMMY' );
}
}
else
{
print "Input emails one per line.<br>";
print "<form action='$_SERVER[PHP_SELF].php' method='post'>";
print "Email to add:<br>";
print "<textarea type='text' name='emails' cols=\"30\" rows=\"30\"></textarea><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
print "</td></tr></table>";
}
?>
something like that then .....
midwesthosting
April 26th, 2007, 18:39
Works,But dont seperate them this is for adding emails in The database,And when it ads them it going all in one Line like
email@site.comemail@site.comemail@site.comemail@site.comemai l@site.comemail@site.comemail@site.comemail@site.comemail@si te.comemail@site.com
If i can get them into seperate lines in the database then that Would work Great
krakjoe
April 27th, 2007, 02:54
one email per line, it works
midwesthosting
April 27th, 2007, 03:25
Dont work
dahitmaka@aol.com
cloud9_618@yahoo.com
datharrisboy@yahoo.com
dionne_24@hotmail.com
djswigga02@aol.com
snyperthugs@tmail.com
stlgoodwood@yahoo.com
SCook66@aol.com
dave72130@yahoo.com
Doing like that
Say's
Cannot email dahitmaka@aol.comrncloud9_618@yahoo.comrndatharrisboy@yahoo. comrndionne_24@hotmail.comrndjswigga02@aol.comrnsnyperthugs@ tmail.comrnstlgoodwood@yahoo.comrnSCook66@aol.comrndave72130 @yahoo.com, bailing
Show's Up like this in Mysql
dahitmaka@aol.comrncloud9_618@yahoo.comrndatharris... 1 8e3dcacbef29f61ba5a7b3731c64dbeb
krakjoe
April 27th, 2007, 04:47
do you use a mac or something ???
I tested the code already and it does actually work, if you send me the location of it and a login I'll have a look, but infact the code is too simple to not work, it just splits the text area by lines and performs the same operation as you did before.
if you can't send a login and still can't get it to work then try writing your own code, you have to do something like
if( $_POST['emailtextarea'] ):
foreach( split("\n", $_POST['emailtextarea']) as $email )
{
// the actions here
}
endif;
with the same code you had before, you might also need to trim() the values...
the only thing I can think of is that line endings are not being sent with the browser or recieved by the server, sometimes macs do that, theres an ini setting in php to fix it
midwesthosting
April 27th, 2007, 05:53
Joe fixed it for me.Thank's Alot man
You should consider doing this for a living,I See you posting all the time helping people with php you Could make alot of money at this
krakjoe
April 27th, 2007, 06:34
lol, I do make a lotta money outa it .....
midwesthosting
April 27th, 2007, 16:18
Good deal then :)
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.