1

I have a page, where people can sign up with name and mail to a waitinglist. When they write the info, the backend add it to my db and I have an admin-page to show the list. But I would like to recieve a mail, when a new user has submittet. I tried this:

$msg = "New user";
mail('my_mail@hotmail.com', 'New user', $msg);

But that didn't send anything. I know Joomla have its own mail-system with JFactory, but I don't understand how I should set it up.

Can anyone help me out?

3

To use JMailer it is pretty simple. The code below should work for you. Just change the appropriate email address and name sections to get it to work.

$subject = "New User Signup";  
$msg = "New user";
$to = "my_mail@hotmail.com";
$from = array("YOUR_EMAIL@YOURDOMAIN.COM", "YOUR NAME");

$mailer = JFactory::getMailer();
$mailer->setSender($from);
$mailer->addRecipient($to);
$mailer->setSubject($subject);
$mailer->setBody($msg);
$mailer->isHtml();
$mailer->send();

You can read more about the Joomla JMailer class here: https://api.joomla.org/cms-3/classes/Joomla.CMS.Mail.Mail.html

  • Just tried adding this code to the backend including $mailer = JFactory::getMailer(); but I still doesn't recieve any mail on execution. – Daniel Jensen May 11 '18 at 9:38
  • Oh, made it work :D Made a mistake copying :) Thank you. Only problem now is, that the mail I recieve says "SPAM" .... – Daniel Jensen May 11 '18 at 9:49
  • 1
    @Daniel Jensen - go to Global Configuration and use SMTP in the mail settings as opposed to PHPMailer. This may fix the spam issue. Also be sure to use proper subject lines and ones that do not contain spam keywords – Lodder May 11 '18 at 16:59
  • 1
    You can also make sure you have proper SPF records for your server and DKIM keys setup in your DNS to help with emails that are mislabeled as spam. – Terry Carter May 11 '18 at 17:11
  • @lodder Didn't help changing to SMTP. Only ends up in spam when I send using this form from my question. Sending test mail or using AcyMailing works fine. – Daniel Jensen May 13 '18 at 5:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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