Guest User

Untitled

a guest
Jun 27th, 2016
62
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. $subject = "Test Email";
  8. $body = "This is only a test.";
  9. $headers = "From: [email protected]\r\n".
  10. "Reply-To: [email protected]\r\n";
  11. $cc = null;
  12. $bcc = null;
  13. $return_path = "[email protected]";
  14. //send the email using IMAP
  15. $a = imap_mail($to, $subject, $body, $headers, $cc, $bcc, $return_path);
  16. echo "Email sent!<br />";
  17.  
  18. // connect to the email account
  19. $mbox = imap_open("{imap.gmail.com:993/imap/ssl}", "[email protected]", "runnableemail");
  20.  
  21. // save the sent email to your Sent folder by just passing a string composed
  22. // of the entire message + headers.
  23. // Notice the 'r' format for the date function, which formats the date correctly for messaging.
  24.  
  25. imap_append($mbox, "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail",
  26. "From: [email protected]\r\n".
  27. "To: ".$to."\r\n".
  28. "Subject: ".$subject."\r\n".
  29. "Date: ".date("r", strtotime("now"))."\r\n".
  30. "\r\n".
  31. $body.
  32. "\r\n"
  33. );
  34. echo "Message saved to Send folder!<br />";
  35.  
  36. // close mail connection.
  37. imap_close($mbox);
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment