0

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?

4
  • 1
    I don't think this is WP specific and should probably better be asked at serverfault or another sibling site. In the end the question boils down to "How can PHP send mails locally?". Trying to answer it: Does it need to? Locally all my sites aren't sending mails via the internet, instead I'm using Mailhog with mhsendmail. For WP context: You could install a mail plugin and use real SMTP connection over PHP's mail() method. What do you want to achieve?
    – kero
    Dec 20, 2021 at 10:53
  • I'd like to achieve testing sending emails from wordpress, installed locally on a mac. Seems to be specific, as other WP users might have faced this configuration issue. BTW I'd rather avoid using plugins for this
    – Riccardo
    Dec 20, 2021 at 12:13
  • Sending mails to where? Globally, or you just want to know if WP sent the mail and have a look at it?
    – kero
    Dec 20, 2021 at 13:36
  • Anywhere. I just need to play with the "Send Reset Link" button in the Admin dashboard, which is broken on the production site.
    – Riccardo
    Dec 20, 2021 at 16:36

1 Answer 1

3

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.

6
  • 1
    Thanks mate! I need Gmail BTW, why this is not working on your end?
    – Riccardo
    Dec 21, 2021 at 9:15
  • 1
    Who closed this topic should notice that it was a specific question to Wordpress, based on the upvotes!
    – Riccardo
    Dec 21, 2021 at 9:37
  • with custom company emails, hotmail it all works wonderful, when I use my gmail, I change the port, smtpauth, smtpsecure, smtphost, all the definitions to gmail, but then I'm not receiving the emails. I really do not know why, It must be wrong configurations, once every other email works great. if someone has the right configurations for gmail smtp, please share them. would be very appreciated Dec 21, 2021 at 11:17
  • 1
    Tiago, I had that filter in my setup already, and it works. You miss $mail->SMTPSecure = "tls";
    – Riccardo
    Dec 22, 2021 at 8:40
  • 1
    add_action( 'phpmailer_init', 'my_phpmailer_example',5 ); function my_phpmailer_example( $phpmailer ) { $phpmailer->isSMTP(); $phpmailer->Host = 'smtp.gmail.com'; $phpmailer->SMTPAuth = true; // Force it to use Username and Password to authenticate $phpmailer->Port = 587; $phpmailer->Username = '[email protected]'; $phpmailer->Password = 'thepassword'; // Additional settings… $phpmailer->SMTPSecure = "tls"; // Choose SSL or TLS, if necessary for your server $phpmailer->From = "[email protected]"; //$phpmailer->FromName = "A mailer service"; }
    – Riccardo
    Dec 22, 2021 at 8:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.