fRAiLtY- Posted August 9, 2011 Share Posted August 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244307-help-with-mime_mail/ Share on other sites More sharing options...
Makwana Posted August 25, 2011 Share Posted August 25, 2011 Try using PHPSwiftmailer its much easier. Alternatively you could have a go with PHPMailer but swiftmailer has always worked really well for me Quote Link to comment https://forums.phpfreaks.com/topic/244307-help-with-mime_mail/#findComment-1261962 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.