Send mail using Pear:Mail

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

Use the pear mail package.

include(‘Mail.php’);

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

$host = “smtp1.phpwebhosting.com”; // enter the smtp server you wish to use here
$port = “25”; // smtp port
$username = “your_smtp_user@domain.com”; // 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)) {
echo(“

” . $mail->getMessage() . “

“);
} else {
echo(“

Message successfully sent!

“);
}

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

Question:

How do I remove an email address?

Answer:

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”

section.

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

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

Question:

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

Answer:

If you have code like :

$mail->IsSMTP();

and

$mail->Host = "localhost";

in your code. Change it to:

$mail->IsSendmail();

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 :

$mail->IsSendmail();

tells PHPMailer to do this.