Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Sending Email

Hi guys,

Can somebody explain to me on how did the send method get its parameter values, especially the $to, $subject, in the Mail object in the project of @Thien anyway here is the link of his project https://github.com/phpmasterdotcom/sendmail

Thnks :)



32.5k

Hey

I use swift mailer so you understand it via http://www.sitepoint.com/sending-email-with-swift-mailer/



10.7k

For me i am using Sendgrid api for sending emails in my phalcon app. https://sendgrid.com/docs/API%5Reference/index.html

Developers can send up to 100 emails per day for free.

@Thien yes i understand that you used Swift mailer to send email, but my question is, how and where did the $to, $subject get its values in the send method? Sorry to bother you man. :)

@Derek thanks for that suggestion.



32.5k
Accepted
answer
edited Nov '14

Ah

You can call anywhere in some case I call in model when user register accont https://github.com/phpmasterdotcom/sendmail/blob/master/app/models/EmailConfirmations.php#L63

And $to is email of user

big big thanks @Thien :) .

edited Dec '14

@Thien i got some warning message on my screen when sending email and i cannot figure out whats causing it.

Warning: Phalcon\DI\Injectable::__get(): Access to undefined property AppMail::_transport in C:\Users\spilagan20140973\Desktop\xammp1\htdocs\PHALCON\app\mail\AppMail.php on line 30

AppMail.php

<?php

require_once __DIR__ . '/SwiftMail/swift_required.php';

use \Phalcon\Mvc\User\Component,
    \Phalcon\Mvc\View;

class AppMail extends Component{

    /*
     * sends email after register
     * 
     * @param string $to
     * @param string $subject
     * @param string $message
     *
     */
    public function sendMail($to, $subject, $message){

        $mailSettings = $this->config->mail;

        // Create the message
        $message = Swift_Message::newInstance()
            ->setSubject($subject)
            ->setTo($to)
            ->setFrom(array(
                $mailSettings->fromEmail => $mailSettings->fromName
            ))
            ->setBody($message, 'text/html');

            if (!$this->_transport) {
                $this->_transport = Swift_SmtpTransport::newInstance(
                    $mailSettings->smtp->server,
                    $mailSettings->smtp->port,
                    $mailSettings->smtp->security
                )
                    ->setUsername($mailSettings->smtp->username)
                    ->setPassword($mailSettings->smtp->password);
            }
            // Create the Mailer using your created Transport
            $mailer = Swift_Mailer::newInstance($this->_transport);
            return $mailer->send($message);
    }
}

i dont know where to find the _transport method or object and the wierd part is it send the email twice



32.5k

Yes

In class AppMail you need to add property protected variable _transport look like:

    class AppMail extends Component{

    protected $_transport;

    [...]

@Thien thnks, no more warning issues but it still send the email twice. Did u encounter this kind of issue before?



32.5k

Not yet:)

edited Dec '14

owwww no, but anyway thnks 4 ur help :)