Creating messages (ie drafts) in Gmail with IMAP/SMTP?

喜欢而已 提交于 2019-11-29 22:40:21

You might want to look at imap_mail_compose()

Edit This doesn't create the message on the server. You need to use imap_append() also.

Further Edit This seems to work ok:

<?php 
$rootMailBox = "{imap.gmail.com:993/imap/ssl}";
$draftsMailBox = $rootMailBox . '[Google Mail]/Drafts';

$conn = imap_open ($rootMailBox, "sdfsfd@gmail.com", "password") or die("can't connect: " . imap_last_error());

$envelope["to"]  = "test@test.com";
$envelope["subject"]  = "Test Draft";

$part["type"] = TYPETEXT;
$part["subtype"] = "plain";
$part["description"] = "part description";
$part["contents.data"] = "Testing Content";

$body[1] = $part;

$msg = imap_mail_compose($envelope, $body);

if (imap_append($conn, $draftsMailBox, $msg) === false) {
        die( "could not append message: " . imap_last_error() )  ;
}

you should be able to create drafts just by moving the composed message into Drafts floder...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!