Jump to content


Photo

"Undefined Class Name" error??


  • Please log in to reply
4 replies to this topic

#1 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 June 2006 - 11:28 AM

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?

<?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>");
 }
?>


#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 June 2006 - 11:40 AM

Heres a mail sender that allows you to use html in it good luck


<?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);
?> 

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 June 2006 - 11:46 AM

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? :)

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 June 2006 - 12:09 PM

<?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];
 

<?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>");
}
?>
 


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 June 2006 - 12:20 PM

Testing

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

Line 18 appears to be:

$mail = $smtp->send($to, $headers, $body);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users