我正尝试在PHPMailer的帮助下发送电子邮件,除了现在我想在Sent Items
中保留发送邮件的副本之外,其他所有操作都正常。
该网站当前托管在Bluehost中。我尝试按照PHPMailer - GMail的示例进行操作,但卡在了我应该指定的路径上。
以PHPMailer - GMail为例,Sent Items
的路径为:
{imap.gmail.com:993/imap/ssl} [Gmail] /已发送邮件
我不知道应该指定什么路径。在我的代码中,一切正常,仅缺少已发送项目的路径。
<?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!";
}
}
}
?>
答案 0 :(得分:0)
这给我邮件目录的路径列表。
Application.CurrentCulture = new CultureInfo("fa-IR");
radDateTimePicker1.Format = DateTimePickerFormat.Custom;
radDateTimePicker1.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;
使用 $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);
?>
或{imap.mydomain.com}
给我一个错误:
无法连接:imap.mydomain.com的证书失败:服务器 名称与证书不匹配:/ OU =域控制 已验证/ OU =由BlueHost.Com托管,INC / OU = PositiveSSL 通配符/ CN = *。bluehost.com
证书问题,幸运的是,我发现了这个question,最终使用了以下主机:
{imap.mydomain.com/ssl/novalidate-cert}
,我希望将已发送邮件转发到已发送邮件中的路径是:
{imap.mydomain.com/ssl/novalidate-cert} INBOX。已发送