Should I use wp_mail or PHP's mail?
I have an email system that I am making in a WordPress plugin to send the emails with this code:
include(PLUGIN_DIR.'config/class_phpmailer.php');
$email = new PHPMailer();
$email-From = get_option('admin_email');
$email-FromName = 'my name';
$email-Subject = $subject;
$email-Body = $body;
foreach($emails as $mail) {
if(is_email($mail)) {
$email-addAddress($mail);
}
}
if($name) {
$att = PLUGIN_DIR.'uploads/'.date('Ymd').'_'.$name;
$email-AddAttachment($att);
}
// check if email is sent or not
if(!$email-Send()) {
echo "Message was not sent br /PHPMailer Error: " . $email-ErrorInfo;
}
else {
echo "Message has been sent";
$_POST = array();
}
This works great. Tested it online and sends to all the tested emails.
Can I make it like this? I mean, with phpmailer class not native to WP. Is this wrong? Is it best to use native WP phpmailer? If so, how can I do it?
Thanks in advance.