Send mail using Pear:Mail

How can I send mail from php using a specific smtp host, for example, or my private smtp server?

Use the pear mail package.


$from = ““;
$to = ““;
$subject = “Test”;
$body = “Test”;

$host = “”; // enter the smtp server you wish to use here
$port = “25”; // smtp port
$username = “”; // your smtp-auth username
$password = “your_password”; // your smtp-auth password

$headers = array (‘From’ => $from,
‘To’ => $to,
‘Subject’ => $subject);
$smtp = Mail::factory(‘smtp’,
array (‘host’ => $host,
‘port’ => $port,
‘auth’ => true,
‘username’ => $username,
‘password’ => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {

” . $mail->getMessage() . “

} else {

Message successfully sent!


How do I delete an email address? (using qmailadmin)


How do I remove an email address?


If you are using the default email configuration (aka “qmailadmin”), login to your control panel, select the “email” header at the top, followed by the “Configure your email accounts” link.

On the page that comes up, login as :

user: postmaster
password: your postmaster password
domain: the domain for the address you want to delete (no “www” in front)

After you login, choose the type of address (POP3, forward, etc.) under the

“Edit existing address”


Next use the “Delete” link to remove the account.

PHPMailer will not send out mail. I get an error with PHPMailer.


Using PHPMailer, I get errors when sending out mail. Any ideas?


If you have code like :



$mail->Host = "localhost";

in your code. Change it to:


The IsSMTP() call tells PHPMailer to send via your local SMTP server. However in most cases this will not work with-out authenticating yourself. You can use PHPMailer to also do an auth but if you are sending to an SMTP server on the local server (ie. “localhost”) – it is much better to do this via sendmail directly. The call to :


tells PHPMailer to do this.