Jump to content

Help with MIME_Mail


fRAiLtY-

Recommended Posts

Hi, I'm using PEAR MIME_Mail extension to send an e-mail with an attachment, very simple.

 

I for some reason cannot get it to send, being presented with an error. Here's my code:

 

<?php

// Check for submission
if($_SERVER['REQUEST_METHOD'] == 'POST') {

	// Set mail variables
	$hdrs = array(
              'From'    => $_POST['from'],
              'Subject' => $_POST['subject']
              );
	$crlf = "\n";
	$file = $_FILES['attachment']['tmp_name'];
	$file_name = $_FILES['attachment']['name']; 
		// Check for uploaded file
		if (is_uploaded_file($file)) { 
			$fp = fopen($file, "rb"); 
			$data = fread($fp, filesize($file));
			$data = chunk_split(base64_encode($file));
			fclose($fp);
		}

	$mime->setTXTBody($_POST['message']);
	$mime->addAttachment($file, 'text/plain');
	$body = $mime->get();
	$hdrs = $mime->txtHeaders($hdrs);

	// Open CSV file and retrieve e-mail addresses	
	$csv = fopen('test.csv', 'r');
		while (($line = fgetcsv($csv)) !== false) {
				foreach ($line as $email) {
					$mail =& Mail::factory('mail');
					$mail->send('postmaster@localhost', $hdrs, $body);
						echo "Mail sent to " . $email . "<br>";
					sleep($seconds);
				}
		}
	fclose($csv);
	echo "<p>Mails sent. Go <a href='csv.php'>Back</a></p>";
} else {

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
<title>Send E-mails from CSV</title>
</head>

<body>

<table height="250" cellpadding="1">
	<tr>
		<td valign="top">
			<form enctype="multipart/form-data" action="csv.php" method="POST">
				<div align="center"> 
					<table cellpadding="0" border="0" align="left">
						<tr>
							<td>Subject:</td>
							<td><input type="text" align="left" name="subject" size="66"></td>
						</tr>
						<tr>
							<td align="left" valign="top">Message Text:</td>
							<td align="left"><textarea name="message" rows="15" cols="60"></textarea></td>
						</tr>
						<tr>
							<td align="left" colspan="2">Seconds between messages:<input type="text" size="10" name="seconds" value="0.1"> (seconds)</td>
						</tr>
						<tr>
							<td align="left" colspan="2">Send from name:<input type="text" size="30" name="from"></td>
						</tr>
						<tr>
							<td colspan="2" align="left">Attachment: <input type="file" name="attachment" size="50"></td>
						</tr>
						<tr>
							<td colspan="2"><input type="submit" value="Send mails" name="submit" ></td>
						</tr>
				</table>
			</div>
		</td>
	</tr>
</table>
  
<?php

}
  
?>

 

And the error I get is:

 

Fatal error: Call to a member function setTXTBody() on a non-object in /home/bjb/public_html/send/csv.php on line 22

 

If anyone could shed some light on this that would be great!

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/244307-help-with-mime_mail/
Share on other sites

  • 3 weeks later...

Archived

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

×
×
  • 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.