Jump to content

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]
Link to comment
https://forums.phpfreaks.com/topic/12144-undefined-class-name-error/
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]
[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]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.