PHPMailer
From DreamHost
(Redirected from PHPmailer example)
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
- Get the PHPMailer files from sourceforge, you should look for the file named PHPMailer_v5.1.zip (or any version more recent).
- Copy the class.phpmailer.php file your site using an SFTP client.
- 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:
- Follow download instructions above.
- In the SunMailer PHPMailer configuration settings, indicate the path of your class.phpmailer.php file on your Dreamhost site.
- 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
- PHP resources wiki page