Posted: December 16, 2013 at 11:58 pm
|
Hi, My solution was to use mandrill to send all email in one api call. You also need to create an email template in Mandrill. That will also make all your email look nice (html) and have link tracking capabilities. Then install the wpMandrill addon in wp and use the following custom function in your custom_function.php file in eventespresso (change the parameters as needed) All your worpress email will then be sent through mandrill. <code> function espresso_event_reminder($event_id, $email_subject='', $email_text='', $email_id=0) { global $wpdb, $org_options; do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, ''); $count = 0; $SQL = 'SELECT * FROM ' . EVENTS_ATTENDEE_TABLE . ' WHERE event_id =%d GROUP BY lname, fname'; //echo ($SQL); //exit; $attendees = $wpdb->get_results( $wpdb->prepare( $SQL, $event_id )); echo ("sending email... <br>"); //initiate arrays for later use $tmv = array(); $tto = array(); if ($wpdb->num_rows > 0) { foreach ($attendees as $attendee) { $attendee_id = $attendee->id; $attemail = array('attendee_id' => $attendee_id, 'send_admin_email' => 'false', 'send_attendee_email' => 'true', 'custom_data' => array('email_type' => 'reminder', 'email_subject' => $email_subject, 'email_text' => $email_text, 'email_id' => $email_id)); extract($attemail); $multi_reg = empty( $multi_reg ) ? FALSE : $multi_reg; $custom_data = empty( $custom_data ) ? '' : $custom_data; $data = espresso_prepare_email_data($attendee_id, $multi_reg, $custom_data); $usermergedata = array(); $temail = espresso_prepare_email($data); //if email invalid skip sending if (!filter_var($temail['send_to'], FILTER_VALIDATE_EMAIL)) { continue; } $usermergedata[] = array('name' => 'USERCONTENT', 'content' => nl2br($temail['email_body'])); $tmv[] = array( 'rcpt' => $temail['send_to'], 'vars' => $usermergedata ); $tto[] = array( 'email' => $temail['send_to'], 'name' => '' ); $tsubject = $temail['email_subject']; $count++; } //start preparing mandrill send $email_text = '*|USERCONTENT|*'; $message = array( 'subject' => $tsubject, 'from_name' => 'Sender Name', 'from_email' => 'user@yourdomain.com', 'to' => $tto, 'merge' => true, 'merge_vars' => $tmv, 'html' => $email_text ); $mandridresult = wpMandrill::sendEmail( $message, $tags = array('Email Event Attendees'), $template_name = 'yourtemplatenameinmandrill' ); echo ('<pre>'); print_r($mandridresult); echo ('</pre>'); ?> <div id="message" class="updated fade"> <p><strong> <?php echo printf( _n('Email Sent to %d person successfully.', 'Email Sent to %d people successfully.', $count, 'event_espresso'), $count ); ?> </strong></p> </div> <?php return; } else { ?> <div id="message" class="error fade"> <p><strong> <?php _e('No attendee records available.', 'event_espresso'); ?> </strong></p> </div> <?php } }</code> I hope this will be useful for someone. |
|
<pre class=”brush: php; gutter: true; first-line: 1; highlight: []; html-script: false”>function espresso_event_reminder($event_id, $email_subject='', $email_text='', $email_id=0) { $attendees = $wpdb->get_results( $wpdb->prepare( $SQL, $event_id )); //initiate arrays for later use if ($wpdb->num_rows > 0) { $attemail = array('attendee_id' => $attendee_id, 'send_admin_email' => 'false', 'send_attendee_email' => 'true', 'custom_data' => array('email_type' => 'reminder', 'email_subject' => $email_subject, 'email_text' => $email_text, 'email_id' => $email_id)); //if email invalid skip sending $usermergedata[] = array('name' => 'USERCONTENT', 'content' => nl2br($temail['email_body'])); //start mandrill send $mandridresult = wpMandrill::sendEmail( //stop mandrill send |
Thanks for providing your solution! |
|
The support post ‘Useful code: Send bulk email to attendees using mandrill’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.