View Full Version : SMTP Authentication & mail() - Help Required

06-04-2007, 03:48 PM
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:

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 {

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.


06-04-2007, 03:53 PM
There should be a file in the PHP directory called go-pear.bat, just click on it, then follow the directions.

06-04-2007, 03:54 PM
The pear setting in the include path is there by default. It does not mean that the pear framework or any specific pear class is installed.

A lot of servers don't have pear installed, so to create a stand a lone script that will work independent of what is present on the server, I recommend that you use the phpmailer class to do SMTP authentication - http://phpmailer.sourceforge.net/

06-04-2007, 04:37 PM
Thanks for the quick reply. I have downloaded phpmailer and attempted to implement it. Although it is not returning an error, I am not receiving the email. Here is the code I am using (as part of a function):


$mail = new PHPMailer();
$mail->SetLanguage('en', 'language');

$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.mysite.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username"; // SMTP username
$mail->Password = "password"; // SMTP password

$mail->From = "myemail@gmail.com";
$mail->FromName = "MySite.com Mailer";
$mail->AddReplyTo("myemail@gmail.com", "MySite");

$mail->IsHTML(true); // set email format to HTML

$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = "";

echo "Mailer Error: " . $mail->ErrorInfo;
return 0;
} else {
return 1;

Does this code look correct? I've taken it from the PHPMailer documentation. If so, I'm guessing the problem lies elsewhere.

Thanks again,


06-05-2007, 01:40 AM
are you doing this from your local computer ? and if so does your ISP block port 25 ? (mine (the biggest Australian ISP) does)

06-05-2007, 11:47 AM
Hi there and thanks for the reply.

No, I'm executing the script from my webserver (hosting with Acecom). Since posting this thread up, I have actually received some test emails that have been sent - It just takes ~9 hours for them to arrive :confused:

I can't understand why.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum