Edit PHPMailer code to send emails to a single address vs using SMTP / G Suite

I am attempting to simplify a custom Wordpress PHPMailer code to send emails to a single address vs using SMTP / G Suite>

  1. Rewrite code to replace SMTP, retaining current recipient fields, etc.
  2. Use SSL
  3. Note: Switched servers, SMTP was with GoDaddy., trying to avoid setting up on A2 Hosting
require_once($_SERVER["DOCUMENT_ROOT"] . '/wp-blog-header.php');

use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception;

require ABSPATH . '/vendor/autoload.php';

function send_mail($email, $subject, $heading, $member_name, $body) {


$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    // server settings
    $mail->SMTPDebug = 0;
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = '[email protected]';
    $mail->Password = 'password code';
    $mail->SMTPSecure = 'tls';
    $mail->Port = 587;

    // recipients
    $mail->setFrom(SUPPORT_EMAIL, 'Pearls of Wisdom');
    $mail->addAddress($email, $member_name);
    $mail->addReplyTo('[email protected]', 'Pearls of Wisdom');

    // attachments
    // $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    // content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = $subject;
    $mail->Body    = $body;
    // $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    return true;
} catch (Exception $e) {
    return false;
}


}

Is there a question? Error? Issue?

Yes!

Read the numbered items in original post.

I want to use a single email address embedded into code vs using SMTP. Not sure how to convert the existing code presented.

It presently sends email to whomever is passed to it. In order to send email to anyone, you have to either send it to an smtp, or send it to a service. So, you want to use the servers smtp rather than googles?

To use SSL, you just need to specify that and the correct port:

smtp.gmail.com
Use Authentication : Yes
Port for SSL: : 465 or 587

Sponsor our Newsletter | Privacy Policy | Terms of Service