Monday, 15 April 2013

Using PHP/MySQL to automate email campaign, not sure how to structure query -


I have two MySQL tables, one with customer details, the other where I monitor those emails sent to The campaign, the version, etc. (Crawler and sent mail, respectively) I have created a script which can send emails on the basis of the SendGrid API, a web form and some javascript by going from the crawler table. But I am trying to figure out how I can tell the script to pull emails from the crawler table, which does not have the campaign listed in the currently sent_mail table. I know that I have to use joining, but in reality it is not known how to create arguments in the query. idea? My attempt is below:

  foreach ('Selection crawler sends email except crawler, sends out quitting mail, crawler.mail = sent_mail.email where sent_mail.campaigns & Lt; & gt; "$ campaign" ') $ address) as $ address) {$ email = New SendGrid \ email (); $ Email - & gt; Ad-tie ($ address) - & gt; Setfram ($ address) - & gt; Setsmack ($ title) - & gt; Set Text ($ text) - & gt; Set HFML ($ text); $ Sendgrid-> Send ($ email); $ Db- & gt; $ Query = "Include Sent Emails (Email, Campaign, Campaign_Version) values ​​($ address, $ campaign, $ campaign_version)"; Echo 'great success'; }   

I think you're looking for code below .. I think The code below can help a bit. $ get_records = mysql_query (Select 'crawler.' Leave crawler as 'email_val'; Skip the crawler mail sent. ($ Data = mysql_fetch_assoc ($ get_records)); $ $ = $ data ['email_val']; $ subject where sent_mail.campaigns & lt; & gt; $ campaign "'); $ I = 1; = 'Content of your topic'; // Always send content to HTML Type $ headers = "MIME-Version: 1.0" "\ r \ n"; $ header. = "Content-type: text / html; Charset = UTF-8 "" \ r \ n "; // More Header $ header. = 'From: Your name & lt; you@you.com>' $ $ Sendmail = Mail ($ $ $ $ theme, $ message, $ header); if ($ sendmail) {$ insert = mysql_query ("Emails sent to them (email, campaign, campaign_version) ('Your value', 'your value', 'your value');); if ($ insert) {echo $ i.'Value insert & mail '. $ Data [' email '] was sent;} Else {echo $ i.'Value has not been included but '$ data [' email '] has been sent to the mail;}} and {echo $ i.' Failed to send mail '. $ Data [' email ' ];} $ I ++;}

Note: Before running the above code, make sure to come Has established a database connection


No comments:

Post a Comment