Hey all, I've run into a litle problem. I have a mailing manager that I grabbed off a site (multi-mail) and it sends out all my e-mails with no problems. My problem is this, it allows you to enter in the body of the e-mail in html but what I want is to put dynamic links into the body, not just 1 standard body text for all the e-mails. This is the line I have written...
$body .= "\r\n\r\n" . stripslashes($myfooter[footer]) . "\r\n\r\n <br><br>" . stripslashes($msg_remove) . " <a href=http://" . $base . $mail_loc.">here</a>";
What it does is adds a link at the bottom of the body that has a dynamic link to drop someone off the mailing list. Now when I send this E-Mail, the links do get dynamically generated, but it adds ALL links to ALL e-mails. Any info on how I can send out the socket one at a time and not all at once. Below is the code....a little long, but it should help a little.
function open_socket($socket, $from) {
global $smtp_id;
fputs($socket,"EHLO $smtp_id\r\n");
fputs($socket,"mail from: $from\r\n");
}
Write the message to the socket, called for each addy
function write_current_mail($socket, $email) {
fputs($socket,"rcpt to: $email\r\n");
}
Close the socket, ie send the message, only called once
If the script pukes out before this point the email is NOT sent
function close_socket($socket, $header, $subject, $body) {
$body = word_wrap($body, 900);
fputs($socket,"data\r\n");
fputs($socket,"Subject: $subject\r\n");
fputs($socket,"To: $email\r\n");
html mail, done in header, just here for ref
#fputs($socket,"MIME-Version: 1.0\r\n");
#fputs($socket,"Content-Type: text/html\r\n");
fputs($socket,"$header\r\n");
fputs($socket,"\r\n");
fputs($socket,"$body\r\n");
fputs($socket,".\r\n");
fputs($socket, "RSET\r\n");
fputs($socket, "QUIT\r\n");
while(!feof($socket)){
fgets($socket, "1024");
}
fclose($socket);
}
Send the message to the correct people
function send_mail(){
global $db, $new_subject, $new_mail, $HTTP_POST_VARS, $footer, $mail_admin, $smtp_server, $mail_admin_alias, $base;
global $sending_mail, $send_sucess, $socket_crash, $mail_loc, $send_html_mail, $msg_remove;
global $use_stmp, $use_std;
echo"$sending_mail<br><br>";
flush();
$result_list = mysql_query("SELECT * FROM lists ORDER BY id DESC") or die(mysql_error());
This could be a for loop but convention in this script is to
do this with a while
$i = 0;
while ($myrow = mysql_fetch_array($result_list)) {
$var = $myrow["list_name"];
$id = $myrow["id"];
reset ($HTTP_POST_VARS);
if($HTTP_POST_VARS[$var]){
Only one footer can be sent, so this doesn't matter.
This reasons that the first list you create will be your most
popular, so the list with the smallest ID (Created first) will be
the one that gets it's footer sent with mailings that go to multiple
lists.
$footer = mysql_query("SELECT footer FROM lists WHERE id='$id'");
$lists_to_send[$i] = get_list_name($id);
$i++;
}
}
$myfooter = mysql_fetch_array($footer);
$result_list = mysql_query("SELECT FROM lists") or die(mysql_error());
$result_user = mysql_query("SELECT FROM mail_list");
if($use_pop) {
$new_mail .= $msg_remove2;
}
$nice_mail = $mail_admin_alias . " <" . $mail_admin . ">";
$header = "From: " . $nice_mail ."\r\nX-Sender: " . $mail_admin ."\r\n Reply-To: " . $mail_admin . "\r\nX-Mailer: 452-PHP 452productions.com";
if($send_html_mail){
$header .= "\r\nMIME-Version: 1.0\r\nContent-Type: text/html\r\n";
}
# Hey, it finnaly works the way it should, unlimited number of lists
# and no regex's w00t w00t
# Try each e-mail address
if($use_std){
# sissy not using sockets
while(($myrow_send = mysql_fetch_array($result_user))) {
# for each address, try each list
while (list($index, $subarray) = each($lists_to_send) ) {
# if the list matchs one they want to recevie send
if($myrow_send[$subarray] == 1){
$email = stripslashes($myrow_send["email"]);
//echo"send $email<br>";
mail($email, $new_subject, $new_mail, $header);
# and we've sent one copy so we don't care about the rest, move
# on to a different address.
break 1;
}
}
reset($lists_to_send);
}
} else {
# now here's a real man (or woman, or 'it' if you live in san fransico)
$socket = fsockopen($smtp_server, 25, $errno, $errstr);
if ($socket) {
open_socket($socket, $mail_admin);
while(($myrow_send = mysql_fetch_array($result_user))) {
# for each address, try each list
while (list($index, $subarray) = each($lists_to_send) ) {
# if the list matchs one they want to receive send
if($myrow_send[$subarray] == 1){
$email = stripslashes($myrow_send["email"]);
$email_id = stripslashes($myrow_send["id"]);
//echo"send $email<br>";
//
//THIS IS THE LINE I WANT TO ADD HERE
//
//$new_mail .= "\r\n\r\n" . stripslashes($myfooter[footer]) . "\r\n\r\n <br><br>" . stripslashes($msg_remove) . " <a href=http://" . $base . $mail_loc . "?a=d&v=" . $email_id . "&e=" . $email .">here</a>";
write_current_mail($socket, $email);
# and we've sent one copy so we don't care about the rest, move
# on to a different address.
break 1;
}
}
reset($lists_to_send);
}
close_socket($socket, $header, $new_subject, $new_mail);
echo"$send_sucess<br><br>";
} else {
echo"$socket_crash";
}
}
}