PHPMailer

From DreamHost
(Redirected from PHPmailer example)
Jump to: navigation, search

PHPMailer is a PHP email transport class featuring file attachments, SMTP servers, CCs, BCCs, HTML messages, word wrap, and more. Sends email via sendmail, PHP mail(), QMail, or with SMTP.


Contents

Download and installation

  1. Get the PHPMailer files from sourceforge, you should look for the file named PHPMailer_v5.1.zip (or any version more recent).
  2. Copy the class.phpmailer.php file your site using an SFTP client.
  3. Use PHPMailer according to your needs.


Use examples

Basic code example

This basic code will send emails.

        require("(location of files)/class.phpmailer.php");
	$mail = new PHPMailer();
			
	$mail->IsSMTP();                                      // set mailer to use SMTP
	$mail->Host = "localhost";  // specify main and backup server
	$mail->SMTPAuth = false;     // turn off SMTP authentication
			
	$mail->From = "me@mydomain";
	$mail->FromName = "Your Name";
	$mail->AddAddress("recipient@theirdomain", "Their Name");

	$mail->AddReplyTo("me@mydomain", "me");
			
	$mail->WordWrap = 50;                                 // set word wrap to 50 characters
	$mail->IsHTML(true);                                  // set email format to HTML
			
	$mail->Subject = "PHPmailer example";
	$mail->Body    = "This is a test of email";
						
	if(!$mail->Send()){
		echo "Message could not be sent. <p>";
		echo "Mailer Error: " . $mail->ErrorInfo;
		exit;
	}

More examples are available at http://phpmailer.sourceforge.net/tutorial.html .


Using PHPMailer with Drupal's SunMailer

Drupal's SunMailer module requires PHPMailer. To set up PHPMailer for SunMailer:

  1. Follow download instructions above.
  2. In the SunMailer PHPMailer configuration settings, indicate the path of your class.phpmailer.php file on your Dreamhost site.
  3. In the SunMailer PHPMailer configuration settings, indicate a test email address and click "Send test email"


Important Information

Any bulk email of any kind sent from a DreamHost account is subject to the DreamHost spam policy which is part of the terms of service.


See also

Personal tools