Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global $wpdb;
- $limit = get_option('limit_emails');
- $table_queue = $wpdb->prefix.'table_name';
- $query = $wpdb->prepare("SELECT * FROM $table_queue ORDER BY ID ASC LIMIT %d", $limit);
- $rows = $wpdb->get_results($query);
- if($rows && get_option('smtp_user') && get_option('smtp_pass') && get_option('smtp_host') && get_option('smtp_port')) {
- $code = $rows[0]->code;
- $message = $rows[0]->texto;
- $attach = $rows[0]->attach;
- $subject = $rows[0]->subject;
- $emails_to = [];
- foreach($rows as $row) {
- if($row->code == $code) {
- array_push($emails_to, $row->email);
- }
- }
- // SEND EMAIL CODE
- include(PLUGIN_DIR.'vendor/PHPMailerAutoload.php');
- include(PLUGIN_DIR.'vendor/class.smtp.php');
- $email = new PHPMailer();
- $email->IsSMTP();
- $email->SMTPAuth = true;
- $email->SMTPKeepAlive = true;
- $email->Host = get_option('smtp_host');
- $email->Port = get_option('smtp_port');
- $email->Username = get_option('smtp_user');
- $email->Password = get_option('smtp_pass');
- $email->SMTPSecure = 'ssl';
- $email->setFrom(get_option('admin_email'), 'name here');
- $email->addReplyTo(get_option('admin_email'), 'name here');
- $email->Subject = esc_html($subject);
- $email->Body = esc_html($message);
- // Set the Atatchment
- if($attach) {
- $att = PLUGIN_DIR.'uploads/'.$attach;
- $email->AddAttachment(esc_html($att));
- }
- // set the emails to send the message
- foreach($emails_to as $mail) {
- if(is_email($mail)) {
- $email->addAddress($mail);
- }
- }
- // send the email
- if(!$email->Send()) {
- echo "Message was not sent <br />PHPMailer Error: " . $email->ErrorInfo;
- }
- else {
- echo "Message has been sent";
- }
- $mail->clearAddresses();
- $mail->clearAttachments();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement