Brinkster Knowledge Base

KB Home   /  Support  /  Code Snippets  /  Email  /   How do I send email with PHPMailer on Linux Hosting
How do I send email with PHPMailer on Linux Hosting Articles
The samples below show how to send email from a Brinkster hosted web site through the supported email components.

Special Note
Be sure to make the following changes when using these coding examples:
1. Replace servername with the server name your site is hosted on.
2. Replace username with your Brinkster account username.
3. Replace YourDomain.com with a valid Brinkster hosted domain name.
4. Replace you@domain.com with a valid Brinkster hosted email account.
5. Replace password with the password for the email account used above.
6. Replace user@domain.com with a valid email account.

**Your FROM address must be the same as the email address you authenticate with.**


PHPMailer:

<?PHP

 

require("/sites/servername/username/home/includes/class.phpmailer.php");

 

$mail = new PHPMailer();

 

$mail->IsSMTP();

$mail->Host = "mymail.brinkster.com";

$mail->SMTPAuth = true;

$mail->Username = "you@domain.com";

$mail->Password = "password";

 

$mail->From = "you@domain.com";

$mail->FromName = "Your Name";

$mail->AddAddress("user@domain.com", "Display Name");

 

$mail->IsHTML(true);

 

$mail->Subject = "Test message sent using the PHPMailer component";

$mail->Body    = "This is a test message.";

 

if(!$mail->Send())

{

   echo "Message could not be sent. <p>";

   echo "Mailer Error: " . $mail->ErrorInfo;

   exit;

}

 

echo "Message has been sent";

?>

 
Below is a sample that includes a form. Copy and paste the code into a PHP page and make the appropriate changes to the mail server, email addresses, and password. 

<html>
<title>Contact</title>
<body>
<br><br>

<?php

if(isset($_POST["Submit"]))
{
/////////////////////////////////////////////////////////////
// Customize the following line with your own information. //
/////////////////////////////////////////////////////////////
require("/sites/servername/username/home/includes/class.phpmailer.php");

$mail = new PHPMailer();

////////////////////////////////////////////////////////////////
// Customize the following 5 lines with your own information. //
////////////////////////////////////////////////////////////////

$toaddress = "Email@Domain.com";  //Change this to the email address you will be receiving your notices.
$mailhost = "mail.yourdomain.com";  //Change this to your actual Domain name.
$fromaddress = "You@Yourdomain.com";  //Change this to the email address you will use to send and authenticate with.
$frompwd = "password";  //Change this to the above email addresses password.
$subject = "PHP Contact Form";  //Change this to your own email message subject.

//////////////////////////////////////////
// DO NOT CHANGE ANYTHING PAST THIS LINE//
//////////////////////////////////////////

$fromname = $_POST["TName"];
$body = $_POST["TBody"] ;
$rplyto = $_POST["TEmail"];
$msgbody = $fromname . "<br>" . $rplyto . "<br>" . $body;

$mail->IsSMTP();
$mail->Host = $mailhost;
$mail->SMTPAuth = true;
$mail->Username = $fromaddress;
$mail->Password = $frompwd;

$mail->From = $fromaddress;
$mail->FromName = $fromname;
$mail->AddReplyTo($rplyto);
$mail->AddAddress($toaddress);
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $msgbody;

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}
 
echo "Thank you, your message has been sent!";
}

?>

 

<form name="SendEmail01" method="post">
<table border=0>
<tr>
 <td>Name:</td>
 <td><input type="text" name="TName" size="30"></td>
</tr>
<tr>
 <td>Email:</td>
 <td><input type="text" name="TEmail" size="30"></td>
</tr>
<tr>
 <td>Body:</td>
 <td><textarea rows="4" name="TBody" cols="30"></textarea></td>
</tr>
<tr>
 <td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</form>
</body></html>