Question

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

Was it helpful?

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

OTHER TIPS

the factories parameters are only used for the smtp autentication. in my experience, most of the clients don't accept mails launched from sites different that the one defined in the email.

for example,

param:
    host:       smtp.example.com
    port:       25
    username:   mail@example.com
    password:   123

could send with no problem mails from anything@example.com, but couldn't send them from anything@otherdomain.com. It will be rejected in most cases.

the same goes when the host is localhost, it will only work fine if you use the domain that is hosting your application.

param:
        host:       localhost
        port:       25
        username:   mail@localorassociatedmail.com
        password:   123

if hosted on aaa.com, it will only work fine with the From: set to anything@aaa.com.

I'm not suer if it's considered spam, in some cases it doesn't even go out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top