我使用 PhpMailer 发送邮件,但我想将邮件保存在我的 webmail 和 Outlook 的“已发送”文件夹中。我有一个脚本,但它无法打开 (imap_open) 文件。
什么是正确的路径?
这是脚本:
<?php
require($_SERVER['DOCUMENT_ROOT'].'/admin/PHPMailer/class.phpmailer.php');
require($_SERVER['DOCUMENT_ROOT'].'/adminPHPMailer/PHPMailerAutoload.php');
class Mailer extends PHPMailer {
public function copyToFolder($folderPath = null) {
$message = $this->MIMEHeader . $this->MIMEBody;
$path = "/." . (isset($folderPath) && !is_null($folderPath) ? ".".$folderPath : ""); // Location to save the email
//$imapStream = imap_open("{" . $this->Host . "}" . $path , $this->Username, $this->Password);
$imapStream = imap_open("{" . $this->Host . "}" . $path ,"address@mydomain.com", "password");
imap_append($imapStream, "{" . $this->Host . "}" . $path, $message);
imap_close($imapStream);
}
}
$mail = new Mailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "localhost"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port
$mail->Username = "address@mydomain.com"; // SMTP account username
$mail->Password = "password"; // SMTP account password
$mail->From = "address@mydomain.com";
$mail->FromName = "Don Joe";
$mail->AddAddress("to@gmail.com");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "tárgy";
$mail->Body = $message;
$mail->AltBody = $message;
if(!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}else{
$mail->copyToFolder(); // Will save into inbox
$mail->copyToFolder("Sent"); // Will save into Sent folder
}
?>
我在服务器上的文件结构:
0:/mail/mydomain.com/address/.Sent
我的网站:
0:/public_html/mydomain.com (this is root of my website under my domain)
我的网络客户端配置:
Username: address@mydomain.com
Password : password
Incoming server: mail.mydomain.com
IMAP port: 143
POP3 port: 110
Outgoing server: mail.mydomain.com
SMTP port: 26
错误信息:
警告:imap_open() [function.imap-open]:无法打开流
警告:imap_append() 期望参数 1 是资源,布尔值在
警告:imap_close() 期望参数 1 是资源,布尔值在