Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'Mail.php';
- include 'Mail/mime.php' ;
- $from = "Robert Davis <mymail@gmail.com>";
- $to = "Sam Hill <receiver>";
- $subject = 'Test mime message with an attachment';
- $headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
- $text = 'Text version of email';// text and html versions of email.
- $html = '<html><body>HTML version of email. <strong>This should be bold</strong></body> </html>';
- $file = './sample.txt'; // attachment
- $crlf = "n";
- $mime = new Mail_mime($crlf);
- $mime->setTXTBody($text);
- $mime->setHTMLBody($html);
- $mime->addAttachment($file, 'text/plain');
- //do not ever try to call these lines in reverse order
- $body = $mime->get();
- $headers = $mime->headers($headers);
- $host = "smtp.gmail.com";
- $username = "mymail";
- $password = "mypass";
- $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true 'username' => $username,'password' => $password));
- $mail = $smtp->send($to, $headers, $body);
- if (PEAR::isError($mail)) {
- echo("<p>" . $mail->getMessage() . "</p>");
- }
- else {
- echo("<p>Message successfully sent!</p>");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement