我发送邮件与PhpMailer,但我想将邮件保存在我的网络邮件和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为资源,在
中给出布尔值
答案 0 :(得分:0)
您可以列出邮箱的所有文件夹名称(完整文件夹名称),大多数邮件服务器都有已发送文件夹的名称INBOX.Sent或INBOX.SentItems等。您应该提供全名。