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!

“);
}

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.

Thunderbird will not let me change my outgoing SMTP setting

Question:

I was trying to setup Thunderbird. However when it came to specifying the outgoing server, Thunderbird said it would use my existing Earthlink outgoing server instead of yours. I tried to change this but it will not let me.

Answer:

Hi,

It is really not a problem to use earthlink for your outgoing. In fact many ISP’s (including earthlink) require you to use their outgoing SMTP. They firewall out external SMTP (port 25) to control all mail that leaves their network.

As long as your incoming POP3 is set to your domain with us it will work fine.