简体   繁体   English

Bluehost:PHPMailer 将已发送消息保存在已发送项目中

[英]Bluehost: PHPMailer save sent message in Sent Items

I'm trying to send an email with the help of PHPMailer , everything works fine except now I want to have a copy of the send mail in Sent Items .我正在尝试在PHPMailer的帮助下发送 email ,一切正常,除了现在我想在Sent Items中拥有发送邮件的副本。

The website is currently hosted in Bluehost .该网站目前托管在Bluehost中。 I tried following the example of PHPMailer - GMail but I'm stuck on which path should I specify.我尝试按照PHPMailer 的示例 - GMail但我被困在我应该指定的路径上。

From the example of PHPMailer - GMail the path for Sent Items is:PHPMailer 的示例 - GMail Sent Items的路径是:

{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail {imap.gmail.com:993/imap/ssl}[Gmail]/发送邮件

I don't know what path should I specify.我不知道我应该指定什么路径。 Everything works fine in my code, only the path for the sent item is missing.在我的代码中一切正常,只有已发送项目的路径丢失。

<?php
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

$username = 'john@mydomain.com';
$password = 'password';

function save_mail( $mail ) {
    //path or folder for sent items
    $path = "{imap.mydomain.com:993/imap/ssl}[...]/..."; //what exactly is the path for my sent item.

    //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;
}

function send(){
    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;
    $mail->Host = 'mail.mydomain.com';
    $mail->Port = 465;
    $mail->SMTPSecure = 'ssl';
    $mail->SMTPAuth = true;
    $mail->Username = $username;
    $mail->Password = $password;
    $mail->setFrom( $username, 'John Doe' );
    $mail->addAddress( 'someone@example.com', 'David Doe' );
    $mail->Subject = 'TEST SUBJECT';
    $mail->msgHTML('<b>TEST</b>');
    $mail->AltBody = 'TEST';

    if ( !$mail->send() ) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
        if (save_mail($mail)) {
            echo "Message saved!";
        }
    }
}

?>

Thanks to Max for the idea of imap_list function.感谢Max对于imap_list function 的想法。

This gives me the list of a path for my mail directories.这给了我邮件目录的路径列表。

  $host = '{imap.mydomain.com/ssl/novalidate-cert}';

  $mail = 'support@mydomain.com';
  $pass = 'password';


  $mbox = imap_open($host, $mail, $pass, OP_HALFOPEN)
      or die("can't connect: " . imap_last_error());

$list = imap_list($mbox, $host, "*");
if (is_array($list)) {
    foreach ($list as $val) {
        echo imap_utf7_decode($val) . "\n";
    }
} else {
    echo "imap_list failed: " . imap_last_error() . "\n";
}

imap_close($mbox);

?>

using the {imap.mydomain.com} or {imap.mydomain.com:993/imap/ssl} gives me an error of:使用{imap.mydomain.com}{imap.mydomain.com:993/imap/ssl}给我一个错误:

can't connect: Certificate failure for imap.mydomain.com: Server name does not match certificate: /OU=Domain Control Validated/OU=Hosted by BlueHost.Com, INC/OU=PositiveSSL Wildcard/CN=*.bluehost.com无法连接:Imap.mydomain.com的证书失败:服务器名称不匹配证书:/OU = domain control actory/ou = bluehost.z35d1ed7d1ed7dbe84f52e62e62e152fe0845881d79fcr*posity lirt.posir.potiv*posity lift*posir = pot。

Certificate issue, luckily I found this question and I end up using the following host:证书问题,幸运的是我发现了这个问题,最终我使用了以下主机:

{imap.mydomain.com/ssl/novalidate-cert} {imap.mydomain.com/ssl/novalidate-cert}

and the path I'm looking to forward the sent mail into sent items is:我希望将已发送邮件转发到已发送项目的路径是:

{imap.mydomain.com/ssl/novalidate-cert}INBOX.Sent {imap.mydomain.com/ssl/novalidate-cert}INBOX.Sent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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