Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * PHP IMAP - Send an email using IMAP and save it to the Sent folder
- */
- //for demo purposes we are gonna send an email to ourselves
- $to = "runnable.tests@gmail.com";
- $subject = "Test Email";
- $body = "This is only a test.";
- $headers = "From: runnable.tests@gmail.com\r\n".
- "Reply-To: runnable.tests@gmail.com\r\n";
- $cc = null;
- $bcc = null;
- $return_path = "runnable.tests@gmail.com";
- //send the email using IMAP
- $a = imap_mail($to, $subject, $body, $headers, $cc, $bcc, $return_path);
- echo "Email sent!<br />";
- // connect to the email account
- $mbox = imap_open("{imap.gmail.com:993/imap/ssl}", "runnable.tests@gmail.com", "runnableemail");
- // save the sent email to your Sent folder by just passing a string composed
- // of the entire message + headers.
- // Notice the 'r' format for the date function, which formats the date correctly for messaging.
- imap_append($mbox, "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail",
- "From: runnable.tests@gmail.com\r\n".
- "To: ".$to."\r\n".
- "Subject: ".$subject."\r\n".
- "Date: ".date("r", strtotime("now"))."\r\n".
- "\r\n".
- $body.
- "\r\n"
- );
- echo "Message saved to Send folder!<br />";
- // close mail connection.
- imap_close($mbox);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement