Bluehost:PHPMailer 在已发送邮件中保存已发送邮件
Bluehost: PHPMailer save sent message in Sent Items
我正在尝试在 PHPMailer 的帮助下发送电子邮件,一切正常,只是现在我想在 Sent Items
.
中获得发送邮件的副本
该网站目前托管在 Bluehost. I tried following the example of PHPMailer - GMail,但我不知道应该指定哪个路径。
从 PHPMailer - GMail 的示例中,Sent Items
的路径是:
{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail
我不知道应该指定什么路径。在我的代码中一切正常,只是缺少已发送项目的路径。
<?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!";
}
}
}
?>
感谢 Max for the idea of imap_list 函数。
这为我提供了我的邮件目录的路径列表。
$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: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
证书问题,幸运的是我找到了这个 question 并且我最终使用了以下主机:
{imap.mydomain.com/ssl/novalidate-cert}
我希望将已发送邮件转发到已发送项目的路径是:
{imap.mydomain.com/ssl/novalidate-cert}INBOX.Sent
我正在尝试在 PHPMailer 的帮助下发送电子邮件,一切正常,只是现在我想在 Sent Items
.
该网站目前托管在 Bluehost. I tried following the example of PHPMailer - GMail,但我不知道应该指定哪个路径。
从 PHPMailer - GMail 的示例中,Sent Items
的路径是:
{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail
我不知道应该指定什么路径。在我的代码中一切正常,只是缺少已发送项目的路径。
<?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!";
}
}
}
?>
感谢 Max for the idea of imap_list 函数。
这为我提供了我的邮件目录的路径列表。
$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: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
证书问题,幸运的是我找到了这个 question 并且我最终使用了以下主机:
{imap.mydomain.com/ssl/novalidate-cert}
我希望将已发送邮件转发到已发送项目的路径是:
{imap.mydomain.com/ssl/novalidate-cert}INBOX.Sent