Closed KSas closed 7 years ago
I have created an example on how to do this because I needed it myself.
Would you accept a pull request @Synchro?
Sure, that example looks good.
I created a pull request: #1116
New pull request: #1117
@NiklasBr Thanks mate - good work bro. We need this in PHPMailer!!!
Is this pull request done? The example looks like for gmail only, how can we use it for any emails, for example, email addresses created in cpanel?
Yes, this PR is done. Make it work on any other IMAP service by changing the hostname of the server you connect to.
I am using PHPMailer 6.0.3 The email is sent correcly to the recipient, but not shown in the sent folder of sender. I must be missing a couple of line of codes. Please help me configure it correctly.
This is my code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$fromEmail='email hosted in cpanel';
$MailTo='myemail@gmail.com';
$Subject='Contact meessage from your website';
$Body='<html><head>
</head>
<body>
<p>Hello</p>
<p>There is a new contact messagefrom Github</p>
<p>Hi, We have an answer to your question.</p>
</body></html>';
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->SMTPDebug = 3;
$mail->CharSet = 'UTF-8';
$mail->Host = 'SMTP outgoing server';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = $fromEmail;
$mail->Password = '********';
$mail->setFrom($fromEmail, 'GitHub');
$mail->addAddress($MailTo);
$mail->addReplyTo($fromEmail, 'GitHub');
$mail->isHTML(true);
$mail->Subject = $Subject;
$mail->Body = $Body;
$mail->send();
?>
Whether this happens automatically is up to your mail server, but many do not do it. The way to do it manually is to upload a copy of the message via IMAP. This is outside PHPMailer’s scope, but look at the gmail example provided to see how to do that.
@akadebnath I am using PHPMailer 6.1.3 The email is sent correcly to the recipient, and successfully saved in sent folder. I have my own domain. I am using webmail (RoundCube). I done some changes in @NiklasBr example. Please refer to his example before looking at this method.
May be you already figured out this thing. But I am giving here for others who are searching the same thing.
This is my code:
function save_mail($mail) {
//You can change 'Sent Mail' to any other folder or tag
//Use imap_getmailboxes($imapStream, '/imap/ssl') to retrieve a list of available folders or tags
$path = "{mail.yourdomain.com:993/imap/ssl/novalidate-cert}INBOX.Sent"; // 993 is my IMAP port.
//Tell your server to open an IMAP connection using the same username and password as you used for SMTP
$imapStream = imap_open($path, $mail->Username, $mail->Password);
$result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
imap_close($imapStream);
return $result;
}
Is there a way to move the mail after sending over SMTP to the folder "Sent" on the mailserver? For example, if I write an email with the mobile phone or on the PC, after sending the mail, its already in the Sent-Folder.