1

I have looked a lot for this but cannot find any dedicated solution. Basically I want to do this: How to send email from Craft 3 custom plugin? … but for a Craft 2 plugin.

A how-to for the global email settings would be already helpful, but ideally we would like to use not those SMTP settings in the global email settings but dedicated ones for another email address. Can this be done?

Thanks!

edit August 8th: no ideas? Any help is welcome!

0

I don't think I'm following the 2nd half of your post, but a simple example of sending an email in Craft 2 looks like this:

$emailModel = new Craft\EmailModel();

$emailModel->subject = 'My Subject';
$emailModel->body = 'My Body';
$emailModel->htmlBody = '<html><body>My HTML Body</body></html>';
$emailModel->toEmail = 'abc@xyz.com';

craft()->email->sendEmail($emailModel);
  • Thanks for writing! In the meantime I have already tried this way, but I get a internal server error «Class 'EmailModel' not found». Regarding the 2nd half of my post: I meant how I could change the global settings with server etc. and its from-address to something defined completely in this code? – romadev Aug 12 at 8:04
  • Edited the answer to fix your internal server error. Regarding the 2nd part, you want to permanently change the Craft install's email settings programatically? Or just temporarily for this one request? – Brad Bell Aug 13 at 2:29
  • Thanks! Now the error changes to "Call to undefined function craft()" … About your question: no, no permanent change, but for our two custom plugins I need to change the smtp-from-address to other settings than the global ones, because it needs to go to different recipients. – romadev Aug 13 at 7:24

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.