Using WP_Mail on MacOS 12 (Monterey - M1)

On a brand new Macbook running Monterey (M1), as PHP was removed by Apple on OS 12, I have removed all AMP preinstalled by Apple and installed HomeBrew AMP (with PHP 7.4), which is running perfectly.

Now, as I have setup Wordpress for testing purposes, I am attempting to use Wordpress WP_Mail function, which relies on PHPMailer, which in turn uses PHP Mail command. The latter relies on system specific libraries, and I am bit confused about configuring the correct facility, Mail, SendMail, Mailsend....

Digging the Internet, once upon a time you would achieve this through Postfix or eventually setting up an email account in the System settings for Mail.app , which I would like to avoid, as I only use web mail on browser and hate to have an email client accessing my account.........

In conclusion, on a Monterey M1 machine, Homebrew AMP scenario, is there a way to allow PHPMailer to work, avoiding using Mail.app account?

Topic smtp wp-mail Wordpress

Category Web


Hi I put this function on the functions.php or in a plugin and works for me everywhere, on localhost or in any server. just need to change the strings to your email smtp settings. Only with gmail I could not make it work so far, all the other ones I try it works perfectly.

// Overriding wp smtp email to send smtp emails (no spam emails)
if (! function_exists('email_sender')){
 add_action('phpmailer_init','email_sender');
 function email_sender($mail){
     $mail->SetFrom('[email protected]', 'thenameIwant to appear on the emails sended');
     $mail->Host = 'smtp-mail.outlook.com';
     $mail->Port = 587;
     $mail->SMTPAuth = true;
     $mail->SMTPSecure = 'STARTTLS';
     $mail->Username = '[email protected]';
     $mail->Password = 'mypassword';
     $mail->IsSMTP();
 }
}

then email should work like a charm! I normally use wp_mail() to do it.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.