Hi all,
On a website I am creating, the hosting service provides an SMTP server to use, along with a username and password, but it is not setup to allow the mail() function to be used.
Being able to send emails through PHP is a fundamental part of the site, so I've been searching around and trying to come up with some code to authenticate with the SMTP server to send the email. What I have at the moment is code found on the Internet to perform this task using the PEAR module. I assume this module is installed as the php.ini 'include_path' setting is c:\php4\pear. Please correct me if I am wrong:
Code:
require_once "Mail.php";
$from = "MySite Mailer <admin@mysite.com>";
$to = 'mailto@mailto.com';
$host = "smtp.mysite.com";
$username = "smtp_user";
$password = "smtp_pass";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("Success!");
}
The error I am getting is as follows:
Fatal error: sendmail(): Failed opening required 'Mail.php' (include_path='.;c:\php4\pear')
I do not have a file called Mail.php in my directory listing, but I assumed this would be included by default through PEAR? I have not used PEAR before, so am unsure.
Any help would be much appreciated.
-Will