Skip to content

Instantly share code, notes, and snippets.

@tournasdim
Created June 25, 2013 07:38
Show Gist options
  • Save tournasdim/5856680 to your computer and use it in GitHub Desktop.
Save tournasdim/5856680 to your computer and use it in GitHub Desktop.
Sending mail without attachment using the PHPMailer Class
<?php
/*
First downlaod the library from Google
http://code.google.com/a/apache-extras.org/p/phpmailer/
*/
require_once 'class.phpmailer.php';
$mail = new PHPMailer(true);
$to = "sendmailto@gmail.com";
$subject = "this is a test from phpmailer" ;
$message = "This message was send with the PHP-mailer library and uses the defauld (mail) ";
try {
$mail->AddAddress($to, 'Example To');
$mail->SetFrom('testexample@example.com', 'Example');
$mail->AddReplyTo('example@example.com', 'Example');
$mail->Subject = $subject;
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($message);
$mail->Send();
echo "<p><br>Message Sent OK</br></p>";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment