Jump to content

Archived

This topic is now archived and is closed to further replies.

Michael4172

"Undefined Class Name" error??

Recommended Posts

I'm attempting to use the following piece of code that I've downloaded from the web. However when I run the script it gives me a "Fatal error: Undefined class name 'mail' on line 15'. Any ideas?

[code]
<?php
require_once "test.php";

$from = "<support@abc.net>";
$to = "<abc@abc.net>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "abc.abc.net";
$username = "abc@abc.net";
$password = "abc";

$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>");
}
?>
[/code]

Share this post


Link to post
Share on other sites
Heres a mail sender that allows you to use html in it good luck


[code]
<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
   <tr>
     <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
   </tr>
   <tr>
     <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
   </tr>
   <tr>
     <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
   </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>
[/code]

Share this post


Link to post
Share on other sites
Thanks for the code. However, I'm trying to use the other one since it makes use of SMTP and I don't have that option with just using that code. Any ideas on the original code? :)

Share this post


Link to post
Share on other sites
[code]
<?php

@set_time_limit(0);

require_once 'smtp_mail.php';

$to = "expertphp@yahoo.com";
$from = "from@myaccount.com";
$subject = "Subject here";

$headers = "MIME-Version: 1.0\r\n".
   "Content-type: text/html; charset=iso-8859-1\r\n".
   "From: \"My Name\" <".$from.">\r\n".
   "To: \"Client\" <".$to.">\r\n".
   "Date: ".date("r")."\r\n".
   "Subject: ".$subject."\r\n";

$message = "
<html>
<body>
<b>html message</b><br>
<font color=\"red\">here</font>
<img src=\"http://static.php.net/www.php.net/images/php.gif\"
border=\"0\" alt=\"\">
</body>
</html>
";

$response = smtp_mail($to, $subject, $message, $from, $headers);

if($response[0]) echo "The message has been sent !<br />\n".$response[1];
else echo "The message can not been sent !<br />\n".$response[1];

[/code]

[code]
<?php
require_once "test.php";

$from = "<support@abc.net>";
$to = "<abc@abc.net>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "abc.abc.net";
$username = "abc@abc.net";
$password = "abc";

$headers = array ('From' => $from,'To' => $to,
  'Subject' => $subject);

$smtp = array ('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>");
}
?>

[/code]

Share this post


Link to post
Share on other sites
Testing

Hmmm, I keep getting: Fatal error: Call to a member function on a non-object. on line 18.

Line 18 appears to be:

[code]
$mail = $smtp->send($to, $headers, $body);
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.