I get an "Uncaught error" any time I try to use the mail() function, server is windows shared on hostgator, they tell me it's a known bug with php in windows servers and don't seem to care much, .asp will email fine using cdosys so I have the right settings/auth.
Is there a genuine known problem or are they fobbing me off?
Is there a workaround for a complete newbie?
TIA.
mail() fails on windows server
Moderators: egami, macek, gesf
-
- php-forum Fan User
- Posts: 90
- Joined: Mon Jun 08, 2020 2:00 am
- Contact:
Do you see any other text with your error?
-
- New php-forum User
- Posts: 3
- Joined: Tue Dec 22, 2020 7:49 am
The full error message is:
Line 19 is:
Full code is:
Code: Select all
Fatal error: Uncaught Error: Class 'Mail' not found in D:\InetPub\vhosts\normanboats.net\httpdocs\junk\mail.php:19 Stack trace: #0 {main} thrown in D:\InetPub\vhosts\normanboats.net\httpdocs\junk\mail.php on line 19
Code: Select all
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
Code: Select all
<?php
ini_set("SMTP","asp1mail.win.hostgator.com" );
ini_set('sendmail_from', 'me@domain.net');
require_once "Mail.php";
$from = "me@domain.net";
$to = 'my.email@outlook.com';
$subject = "Hi!";
$body = "Hi,\n\nHow are you?\nphp test";
$host = '127.0.0.1';
$username = 'me@domain.net';
$password = 'Mypa55word';
$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("<p>Message successfully sent!</p>");
}
?>
-
- php-forum Fan User
- Posts: 90
- Joined: Mon Jun 08, 2020 2:00 am
- Contact:
OK. That looks like the file Mail.php is supposed to define a class called "Mail" but it either doesn't or isn't loaded correctly. Is there a "Mail" class defined in Mail.php?
-
- New php-forum User
- Posts: 3
- Joined: Tue Dec 22, 2020 7:49 am
Oops! Sorry I posted the wrong code, that was a later trial of something.
The proper code is:
This is taken straight from hostgators help pages and is the php windows test code they supply but then tell me there's a known bug with windows servers, I would have gone linux but it's a legacy website I took over with an old forum in .asp using an access database file so a bit tied.
The proper code is:
Code: Select all
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,
How are you?";
$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";
$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("<p>Message successfully sent!</p>");
}
?>
-
- php-forum Fan User
- Posts: 90
- Joined: Mon Jun 08, 2020 2:00 am
- Contact:
The problem line is still trying to reference the class "Mail" right? Which isn't found. My first thought is it should be in the required "mail.php". Is that file in the same directory as this script, and does it have the "Mail" class in it?