Jump to content

Recommended Posts

Using simple mail.php script.  Yet I am getting the dreaded Fatal error: Call to undefined method Mail::AddAttachment() in ... error

"Fatal error: Call to undefined method Mail::AddAttachment() in \\...\www\mail.php on line 59"

 

This is mail.php

<?php 
 
class Mail {
    var $parts;
    var $to;
    var $cc;
    var $bcc;
    var $from;
    var $headers;
    var $subject;
    var $body;
    var $html;
    var $host;
    var $port;
 
    function __construct() {
        $this->parts = array();
        $this->to = "";
        $this->cc = "";
        $this->bcc = "";
        $this->from = "";
        $this->subject = "";
        $this->body = "";
        $this->headers = "";
        $this->html = true;
    }
 
 
    function buildMultipart() {
        $boundry = "HKC".md5(uniqid(time()));
        $multipart = "Content-Type: multipart/mixed; boundary =  \"$boundry\"\n\n";
        $multipart .= "This is a MIME encoded message.\n\n--$boundry";
        for($i = sizeof($this->parts)-1; $i >= 0; $i--) {
            $multipart .= "\n".$this->buildMessage($this->parts[$i])."--$boundry";
        }
        return $multipart .= "--\n";
   }
 
    function getMail($complete = true) {
        $mime = "";
        if(!empty($this->from)) {
            $mime .= "From: ".$this->from."\n";
        }
        if(!empty($this->headers)) {
            $mime .= $this->headers."\n";
        }
        if($complete) {
            if(!empty($this->cc)) {
                $mime .= "Cc: ".$this->cc."\n"; 
            }
            if(!empty($this->bcc)) {
                $mime .= "Bcc: ".$this->bcc."\n";
            }
            if(!empty($this->subject)) {
                $mime .= "Subject: ".$this->subject."\n";
            }
        }     
            if(!empty($this->body)) {
                $this->AddAttachment($this->body,"",($this->html?"text/html":"text/plain"));
    }
                $mime .=  "MIME-Version: 1.0\n".$this->buildMultipart();
      return $mime;
    }
 
    function send() {
        if(!empty($this->cc)) {
            $mime = $this->getMail(true);
        } else {
            $mime = $this->getMail(false);
        }
        if(!empty($this->host)) {
             ini_set("SMTP",$this->host);
        }
        return mail($this->to,$this->subject,$this->body,$mime);
    }
}
 
?>

And this is the program that makes the call:


<?php


if (isset($_POST["email"])) {
	$email = $_POST["email"];
	$email= str_replace("'", "''", $email);
	require_once('../database.php');

	$sql="select fa_id,name from freeagents where email='".$email."'";

	$emailSearch = mssqlquery($sql);

	if (!mssqlhasrows($emailSearch))  
	{
		mssqlclose();
		header("Location: http://www.baltimorebeach.com");
		exit();
	}
 

		 
	$row = mssqlfetchassoc($emailSearch);
	mssqlclose();
	$salt=$row["fa_id"].".baltimorebeach.";
	$check=hash('ripemd160', $salt.$email); 
		

$strMailBody = <<<MAILBODY
                                                          
                                                          
Hi $row[name],

<br><br>

A request was made to change your Baltimore beach volleyball free agent 
registration information.

<br><br>

If you want to update your registration information click on 
this link:
http://www.baltimorebeach.com/FreeAgents/registerfreeagent.php?email=$email&check=$check

<br><br>

To remove your name from the Free Agent list  deselect 
all the checkboxes when you update your information.

MAILBODY;

	require_once('../mail.php');

	$message = new Mail();
	$message->from = "noreply@baltimorebeach.com";
	$message->to = $email;
	$message->subject = "Baltimore Beach Volleyball Free Agent Registration Update Link";
	$message->body = $strMailBody;
	$message->html = true;
	$message->send();

}

?>



<html>
<head>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<style type="text/css">
	label.error {
		color:red;
	}
	input.error {
		border:1px solid red;
	}
</style>
<script type="text/javascript">
	$().ready(function () {
		// validate registration form on keyup and submit
		$("#emailform").validate({
			rules: {
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				email: {
					required: "Please enter an email address",
					email: "Please enter a valid email address"
				}
			}
		});
	});
	</script>
</head>
<body>
To update your free agent registration information enter your email to send yourself a baltimorebeach.com url link that will allow you to access your own registration details.
<br>
To remove yourself from the free agent list just deselect all the leagues you have previously selected when updating your information.
<br>
<br>
<?php
if (!isset($_POST["email"])) {
?>
<form id="emailform" action="sendlink.php" method="post">
	E-Mail: <input type="text" id="email" name="email" value=""/>
	<br>
	<input type="submit" id="sumbit" value="Send">
</form>
<?php
} 
else {
echo "E-Mail Sent. "."You will receive an email with the update link at the email address your requested shortly";
}

?>
</body>
</html>

I did not write this code, however the person who did is no longer available to me.  I can't seem to figure out how to remove this error.

Thanks so much!

 

Well, as you can see, there is no AddAttachment() method in the class. And there's nothing you can do about it except programming it yourself.

 

But this code is ancient and pretty bad, anyway. The var keyword tells me it was probably written for PHP 4 somewhere around the year 2000. Let it rest in peace and use a proper mailer library.

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.