OK - I just thought about your statement,
but internally everything goes via send() so plugins do still work.
I have tried to incorporate the new version 4 objects with my newsletter sending script.
Just to explain.
Before a member gets the "current" version of the newsletter, they get two introduction
newsletters which explain certain aspects, then the get the current edition.
To check to see if they need the intros a field is checked in the client table
- you will see this in the code.
Now the bits I am not sure about are:
1) I have called some of the objects just once at the top of the script
- hope thats right.
2) I have placed my variables in the objects like this:
$message->setSubject('$subject'); ???
3) On the text only version I have written new lines
like this: MESSAGE-TEXT = "Dear $contact,/n/n
Hi, /n ";
Again, I don't know if this is correct.
4)
I may not be accessing the array variable propery
to display my failures.
here
<span class= \"lk\">$Rctr ) Failed to Send Edn 1 to :$user_id, at $failures</span>
Hopefully you can point out my errors
Maybe this post will help others as well.
Thanks.
Here is my script:
Code: Select all
<?php
/* member_news.php
*
* Sends newsletter to members.
*
*/
@session_start();
if (@$_SESSION['auth'] != "yes" ){
header("Location: /im/index.php");
exit();
} // end if
// Below is just to set up the display of this page
$page="control";
$title1 ="Control Panel";
$desc = "Controlling your";
require_once("mem_head.php");
// *********************************
require_once("my_functions.php");
require_once("bbcode_email.php");
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.my-site.com', 25)
->setUsername('your username')
->setPassword('your password')
;
$mailer = Swift_Mailer::newInstance($transport);
?>
<div class="page_name">
<h1>Control Panel</h1>
</div> <!-- End div: page_name -->
<div class="pg_whole">
<span class="pg_head">Send Newsletter to Members.</span>
<br><br>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<strong>Do you really want to send the newsletter? </strong>
<input type="submit" value="Yes" name="submit_email">
<input type="button" value="No">
</form>
<?php
if (isset($_POST['submit_email'])) {
$sql = " SELECT * FROM newsletters WHERE confirm = 'y' and status = 'c' and type = 'm'";
$result = mysql_query($sql) or die("could not execute find Newsletters query". mysql_error());
$num = mysql_num_rows($result);
if ($num == 0 ) {
$temp_body = "There is no confirmed, current members newsletter !";
$link1 = "Error: No Confirmed, New Members Newsletter !";
echo "<div class=\"listerdiv\">
<span class= \"lk\">$link1</span>
<span class= \"by\">$temp_body</span>
</div>";
require_once("footer.php");
exit();
} // endif
else{
while($row = mysql_fetch_assoc($result)){
$cur_nws_id = $row[news_id];
$cur_nws_hd = $row[news_head];
$cur_nws_bd = $row[news_body];
} // end while
} // end else
$sql = " SELECT * FROM clients WHERE (type = 'm' || type = 'E') AND confirm = 'y'";
$result = mysql_query($sql) or die("could not execute find Clients query". mysql_error());
$num = mysql_num_rows($result);
if ($num == 0 ) {
$temp_body = "There are no clients !";
$link1 = "No New Members!";
echo "<div class=\"listerdiv\">
<span class= \"lk\">$link1</span>
<span class= \"by\">$temp_body</span>
</div>";
require_once("footer.php");
exit();
} // endif
else{
echo "<div class=\"ctrl_lister\">
<span class= \"lk\">Starting to process clients and send newsletters ...</span>
</div>";
$Rctr = 1;
while($row = mysql_fetch_assoc($result)){
extract($row);
$join_dt = date('j F Y',$create_date);
// Now we check to see if they need need to
// have the first intro newsletter
// - $eml comes from the client record
if ($eml == 1) {
$subject = "$contact: As Promised ...no. 1 Blah blah.";
$message = "<b>Blah blah Newsletter. No. 1</b><br>
Dear $contact,
Hi,
Intro number one
Blah blah Blah blah
Blah blah Blah blah";
$message-text = "Blah blah Newsletter. No. 1/n
Dear $contact,/n/n
Hi, /n
Intro number one /n
Blah blah Blah blah/n
Blah blah Blah blah";
/*
* The code below will go into a separate php file called news_send.php
*/
Swift_Message::newInstance()
// set the sender
$message->setFrom(array('Editor@my-site.com' => 'James Burke'));
// set the recipient
$message->setTo(array('$email' => '$contact'));
// set the subject
$message->setSubject('$subject');
// set the html body
$message->setBody('$message', 'text/html');
// set the text body
$message->addPart('$message-text', 'text/plain');
//Send the message
if (!$mailer->send($message, $failures)) {
echo "<div class=\"ctrl_lister\">
<span class= \"lk\">$Rctr ) Failed to Send Edn 1 to :$user_id, at $failures</span>
</div>";
} // end if
else
// update database
$sql = "UPDATE clients SET eml = eml+1 WHERE user_id = '$user_id'";
mysql_query($sql) or die("could not execute adverts update query". mysql_error());
echo "<div class=\"ctrl_lister\">
<span class= \"lk\">$Rctr ) Sent Edn 1 to :$user_id, Type: $type, Contact: $contact, Joined:$join_dt</span>
</div>";
} // end else
$Rctr = $Rctr +1;
/*
* end of news_send.php
*/
} // end if
// Now we check to see if they need need to
// have second intro newsletter
// - $eml comes from the client record
if ($eml == 2) {
$subject = "$contact: As Promised ...no. 2 Blah blah.";
$message = "<b>Blah blah Newsletter. No. 2</b><br>
Dear $contact,
Hi,
Intro number two
Blah blah Blah blah
Blah blah Blah blah";
$message-text = "Blah blah Newsletter. No. 2/n
Dear $contact,/n/n
Hi, /n
Intro number two /n
Blah blah Blah blah/n
Blah blah Blah blah";
require("news_send.php");
} // end if
// Now we check to see if they need need to
// have the CURRENT newsletter
// - $eml comes from the client record
if ($eml > 2) {
$subject = "$contact: ".$cur_nws_hd;
$message = "Dear $contact: <br>".$cur_nws_bd;
$message=nl2br($message);
$message=eml_bbcode($message);
$message-text = "none yet";
require("news_send.php");
$sent_curr = "y";
} // end if
} // end while
if($sent_curr == "y") {
// update client table
$sql = "UPDATE newsletters SET
confirm = 's',
status = 's',
sent_date = '$today'
WHERE news_id = '$cur_nws_id'";
mysql_query($sql) or die("could not execute newsletters update query". mysql_error());
} // end if
} // end else
} // end if
?>