简体   繁体   中英

PHPMailer Class And Gmail: The sent emails not retain in Sent directory in Gmail

I used PHPMailer class to send emails

http://code.google.com/a/apache-extras.org/p/phpmailer/

The sent emails not retain in Sent directory in Gmail.

Where I'm wrong ?

    try {
    $mail = new PHPMailer(true); //New instance, with exceptions enabled

    $body             = file_get_contents('ct.html');
    $body             = preg_replace('/\\\\/','', $body); //Strip backslashes

        $mail->IsSMTP(); // telling the class to use SMTP
        $mail->Host       = "smtp.gmail.com"; // SMTP server
        $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                                   // 1 = errors and messages
                                                   // 2 = messages only
        $mail->SMTPAuth   = true;                  // enable SMTP authentication
        $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
        $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
        $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
        $mail->Username   = "*******@gmail.com";  // GMAIL username
        $mail->Password   = "*******";            // GMAIL password

        if($mail->SmtpConnect()){
            echo "SmtpConnect";
        }else{
            echo "ERROR";
        }

        $mail->IsSendmail();  // tell the class to use Sendmail

        $mail->AddReplyTo("*******@gmail.com", "*****");

        $mail->From = "*******@gmail.com";
        $mail->FromName = "*******";

        $to = "receiver@*******.***";

    $mail->AddAddress($to);

    $mail->Subject  = "First PHPMailer Message " . rand();

    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
    $mail->WordWrap   = 80; // set word wrap

    $mail->MsgHTML($body);

    $mail->IsHTML(true); // send as HTML

    $mail->Send();
    echo 'Message has been sent.';
} catch (phpmailerException $e) {
    echo $e->errorMessage();
}

How I can storing emails in Sent Directory ?

Thank in advance !

This seems to relate to your problem and it seems that they don't get stored when using smtp. However, you could BCC the sending account and just filter those mails in a separate folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM