Michael4172 Posted June 16, 2006 Share Posted June 16, 2006 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]<?phprequire_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] Quote Link to comment https://forums.phpfreaks.com/topic/12144-undefined-class-name-error/ Share on other sites More sharing options...
redarrow Posted June 16, 2006 Share Posted June 16, 2006 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 itmail($to, $subject, $message, $headers);?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/12144-undefined-class-name-error/#findComment-46233 Share on other sites More sharing options...
Michael4172 Posted June 16, 2006 Author Share Posted June 16, 2006 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? :) Quote Link to comment https://forums.phpfreaks.com/topic/12144-undefined-class-name-error/#findComment-46234 Share on other sites More sharing options...
redarrow Posted June 16, 2006 Share Posted June 16, 2006 [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]<?phprequire_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] Quote Link to comment https://forums.phpfreaks.com/topic/12144-undefined-class-name-error/#findComment-46237 Share on other sites More sharing options...
Michael4172 Posted June 16, 2006 Author Share Posted June 16, 2006 TestingHmmm, 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] Quote Link to comment https://forums.phpfreaks.com/topic/12144-undefined-class-name-error/#findComment-46238 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.