We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Sending Email

Can any one please tell me how to send emails using phalcon framework as I am new to this framework

edited Oct '15

In Phalcon integreted mail function is absent use https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Mailer or https://github.com/vanchelo/phalcon-mailer . First is more tested but second can work with queue. And both depend SwiftMailer

As a side note, the reason Phalcon doesn't have an integrated mail system is because there will be no real advantage of a mailing system written in Zephir. Most of the time is spent sending the emails and not executting the code

can i have to install swift mailer first then add the phalcon library or swift mailer is already installed on phalcon framework.

install swift mailer first and then the phalcon library



17.5k
edited Oct '15

I used SendGrid and it's super simple. You'll need to sign up with sendgrid and include with composer. Simple use as follows:

    public function sendActivationEmail() {
        $sendgrid = new SendGrid('[username]', '[password]');
        $email = new SendGrid\Email();
        $email->addTo($this->email)
            ->setFrom("[email protected]")
            ->setSubject("Sending emails is super neat.")
            ->setHtml("
                <p>Text is awesome for emails!  Love it.</p>
            ");
        $sendgrid->send($email);
    }

This method is called in the user object in the afterCreate(); [username] and [password] are your username and password w/ SendGrid.

Sendgrid also has support for templates and such, but I didn't take the time to figure them out.