Search code examples
drupaldrupal-modulesdrupal-9

Drupal phpmailer custom mail plugin - Error sending email (from xxx to yyy with reply-to not set)


All!

I created a mail plugin with the aim of being able to send html based emails strictly speaking using Twig templates as I learned that the default mail system in Drupal is based on PHP mail and it uses the mail function which does not support html messages However, any attempt by me to add this, text/html; charset=UTF-8, to the Content-Type header of the message will be override within the mail function.

I have created a mail logger specifically to send any errors that may occur via e-mail as well.

Inside the mail plugin that I created, specifically within its mail function, I used the phpmailer library. And I set the data of the SMTP server to the data of my mail-trap SMTP.

The message that I want to actually send is sent, indeed it is sent to the mail-trap inbox, and at Drupal it shows me the result of the successful sending of the message, but below it an error message appears: Unable to send email. Contact the site administrator if the problem persists. And by checking the mail-trap inbox, I find 4 messages that are added to my message, this is their content Error sending email (from xxx to yyy with reply-to not set).

I don't know what is the reason for these messages. Does anyone know what could be causing the problem?


Solution

  • I found out the cause of the problem and it was a personal error from me as I did not pay attention to the definition of the mail function in the MailInterface as it returns a boolean value data type which is the same as the data type returned by the mail function of the phpmailer library so I had to write return $mail-> send() at the end of the class of the custom mail plugin I created. And I was trying to show a message inside the mail function for the custom plugin I was creating and it was causing the problem.