0

I am new to Yii2.. I sent email using Yii2 swift mailer SMTP. Email sent successfully but the sent email is not visible inside sent folder of the email can anybody help me.. here is my code. this is my controller code..

 Yii::$app->mailer->compose()
 ->setFrom('info@abc.com')
 ->setTo('test@gmail.com')
 ->setSubject('Email sent from Yii2-Swiftmailer')
 ->send();

my configuration is

 'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'abc.prod.sin3.secureserver.net',
                'username' => 'info@abc.com',
                'password' => 'xxxxxxxxxx',
                'port' => '465',
                'encryption' => 'ssl',
                            ],
    ],
DON BOSCO
  • 11
  • 2
  • 1
    Any errors? ... – GetSet Dec 13 '20 at 07:14
  • no issue in sending email... but i need to save a copy of email to my send box – DON BOSCO Dec 13 '20 at 07:19
  • From my experience, there is no "auto" save of mails generated from PHP. You would have to code that explicitly. – GetSet Dec 13 '20 at 07:22
  • It is the email client that populates it's SENT folder. Since you are custom coding, there is no explicit code to save to a non-specified SENT folder, or even any custom code for which mail format that should be in. – GetSet Dec 13 '20 at 07:27
  • ok thank you for the quick response... so you have any idea about saving the sent email to send box in Yii2.... – DON BOSCO Dec 13 '20 at 07:35
  • Id suggest saving to your own "mail" file server side. Before actually seeing if the mail is sent successfully. Like a "log". You can write your own "web app" that queries the log. – GetSet Dec 13 '20 at 07:38
  • my client need to see the sent email in sent box... is there any way? – DON BOSCO Dec 13 '20 at 07:54
  • Could always charge client "more" on how this cant be done, but you can make it happen separately? Separately could be a simple loop on a page that iterates his email log that you create on outbound mail from site. – GetSet Dec 13 '20 at 08:49
  • Does this answer your question? [Add mail to Send folder with SwiftMailer](https://stackoverflow.com/questions/19497557/add-mail-to-send-folder-with-swiftmailer) – Michal Hynčica Dec 14 '20 at 08:30

2 Answers2

1

Thank you all for your help. I got a solution for the problem. After an email is sent just call the below code so the email will save on sent folder.

Yii::$app->mailer->compose()
 ->setFrom('info@from.com')
 ->setTo('to@gmail.com')
 ->setSubject('Email sent from Yii2-Swiftmailer')
 ->send();



$mbox = imap_open("{imap.dreamhost.com:143/notls}INBOX", "username", "password");

 imap_append($mbox, "{imap.dreamhost.com:143/notls}INBOX.Sent",
    "From: me@example.com\r\n".
    "To: to@gmail.com\r\n".
    "Subject: Test subject2\r\n".
    "Date: ".date("r", strtotime("now"))."\r\n".
    "\r\n Test body2\r\n"
    );

// close mail connection.
imap_close($mbox);
 return true;

for more details pls refer this link.. https://help.dreamhost.com/hc/en-us/articles/216507288-PHP-IMAP

DON BOSCO
  • 11
  • 2
0

if you to keep any email sent just create an email address for this, for example : emailsent@abc.com then modify your code to :

  Yii::$app->mailer->compose()
 ->setFrom('info@abc.com')
 ->setTo('test@gmail.com')
  >setBcc('emailsent@abc.com')
 ->setSubject('Email sent from Yii2-Swiftmailer')
 ->send();