Make WordPress Core

Opened 13 years ago

Closed 9 years ago

Last modified 9 years ago

#15539 closed defect (bug) (wontfix)

wp_mail() should allow using PHPmailer's SMTP feature

Reported by: mastermind's profile mastermind Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Mail Keywords: has-patch
Focuses: Cc:

Description

wp_mail() is able to use an already existing instance of PHPmailer. Unfortunately, all settings from the existing instance are then reset.

While this makes sense for things like addresses and subject, it is very bad that $phpmailer->IsMail() is called.

This makes it impossible to create and configure an own instance for usage with a remote MTA.

Possible solutions:

  1. Simply omit the call to $phpmailer->IsMail(), as 'mail' is already the default value.
  1. Move the call of $phpmailer->IsMail() into the if statement at the beginning of the wp_mail() function, so it will only be set if the instance is not set.
  1. Add a parameter to the signature of wp_mail() which allows to set the desired MTA backend.

Attachments (1)

15539.diff (411 bytes) - added by solarissmoke 13 years ago.
No need to manually set mailer to the same as the default

Download all attachments as: .zip

Change History (7)

#1 @nacin
13 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

It's best to rely on mail() by default, but other MTAs can be used if desired.

There's a way to handle this by leveraging the do_action_ref_array -- the phpmailer object can be passed to a callback and modified completely.

There's a plugin called WP Mail SMTP that handles this for example.

Re-reading the ticket, I don't object to #2.

#2 @mastermind
13 years ago

Ok, I didn't see the do_action_ref_array() at the bottom of wp_mail() – must have been some sort of blind spot.

I agree that this can be used as a workaround. Still, I think that simply omitting phpmailer->IsMail() would be perfect: mail is the default value of $phpmailer->Mailer, so if the instance is fresh, it will be set anyway; if the instance is pre-set, any other value will be intentional.

#3 @nacin
13 years ago

Right, but setting up the instance on your own really just isn't the best way to hook into this. Rather, modify the object directly on that hook.

@solarissmoke
13 years ago

No need to manually set mailer to the same as the default

#4 @solarissmoke
13 years ago

  • Keywords has-patch added; needs-patch removed

#5 @chriscct7
9 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

This is done by tons of plugins now. WP Mail SMTP is probably the most known of the batch. Re by plugin territory.

#6 @DrewAPicture
9 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.