Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. <?php
  2. /*
  3. * PHP IMAP - Send an email using IMAP and save it to the Sent folder
  4. */
  5.  
  6. //for demo purposes we are gonna send an email to ourselves
  7. $to = "runnable.tests@gmail.com";
  8. $subject = "Test Email";
  9. $body = "This is only a test.";
  10. $headers = "From: runnable.tests@gmail.com\r\n".
  11. "Reply-To: runnable.tests@gmail.com\r\n";
  12. $cc = null;
  13. $bcc = null;
  14. $return_path = "runnable.tests@gmail.com";
  15. //send the email using IMAP
  16. $a = imap_mail($to, $subject, $body, $headers, $cc, $bcc, $return_path);
  17. echo "Email sent!<br />";
  18.  
  19. // connect to the email account
  20. $mbox = imap_open("{imap.gmail.com:993/imap/ssl}", "runnable.tests@gmail.com", "runnableemail");
  21.  
  22. // save the sent email to your Sent folder by just passing a string composed
  23. // of the entire message + headers.
  24. // Notice the 'r' format for the date function, which formats the date correctly for messaging.
  25.  
  26. imap_append($mbox, "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail",
  27. "From: runnable.tests@gmail.com\r\n".
  28. "To: ".$to."\r\n".
  29. "Subject: ".$subject."\r\n".
  30. "Date: ".date("r", strtotime("now"))."\r\n".
  31. "\r\n".
  32. $body.
  33. "\r\n"
  34. );
  35. echo "Message saved to Send folder!<br />";
  36.  
  37. // close mail connection.
  38. imap_close($mbox);
  39.  
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement