Search code examples
phpsymfony-1.4mailer

configurations factories.yml in symfony 1.4


At first i have emial aaa@bbb.com and there is another email doesn't belong to me for example ccc@ddd.com or anything else blabla@bla.com

IN factories.yml i configured the mailer with the following

mailer:
  class: sfMailer
  param:
    logging:           %SF_LOGGING_ENABLED%
    charset:           %SF_CHARSET%
    delivery_strategy: realtime
    transport:
      class: Swift_SmtpTransport
      param:
        host:       smtp.localhost.com
        port:       25
        username:   aaa@bbb.com
        password:   123456

In the code ... to send an email i use

         $message = Swift_Message::newInstance()->setSubject('sub')->setFrom('ccc@ddd.com')->setTo('yahoo@yahoo.com');
         sfContext::getInstance()->getMailer()->send($message);

Now i setFrom() ---> ccc@ddd.com however i configured the factories.yml with another email aaa@bbb.com!!!!

Finally the sent mail is from ccc@ddd.com which isn't my email actually


Solution

  • the factories.yml file details the SMTP details

    param:
        host:       smtp.localhost.com
        port:       25
        username:   aaa@bbb.com
        password:   123456
    

    Here the username is the username used for logging onto the smtp server. Not the email address the email will be sent from.

    This line

    $message = Swift_Message::newInstance()
                      ->setSubject('sub')
                      ->setFrom('ccc@ddd.com')
    

    determines the from address of the email.

    See the docs for swift mailer for the methods