Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

pear php script errors

Posted on 2009-07-15
8
1,106 Views
Last Modified: 2012-05-07
see my accepted solution
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24329557.html
which was about uploading a file for attachment
that works the file gets uploaded
but my script I is failing with
Warning: include_once(/PEAR/Mail.php) [function.include-once]: failed to open stream: No such file or directory in /home/fhlinux198/i/ian.no1net.co.uk/user/htdocs/send-email-form.php on line 10

Warning: include_once() [function.include]: Failed opening '/PEAR/Mail.php' for inclusion (include_path='.:/usr/share/pear-php5') in /home/fhlinux198/i/ian.no1net.co.uk/user/htdocs/send-email-form.php on line 10

Warning: include_once(/PEAR/Mail/mime.php) [function.include-once]: failed to open stream: No such file or directory in /home/fhlinux198/i/ian.no1net.co.uk/user/htdocs/send-email-form.php on line 11

Warning: include_once() [function.include]: Failed opening '/PEAR/Mail/mime.php' for inclusion (include_path='.:/usr/share/pear-php5') in /home/fhlinux198/i/ian.no1net.co.uk/user/htdocs/send-email-form.php on line 11

Fatal error: Class 'Mail_mime' not found in /home/fhlinux198/i/ian.no1net.co.uk/user/htdocs/send-email-form.php on line 85

does that mean pear isn't installed
0
Comment
Question by:IanTh
  • 4
  • 4
8 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 24859509
no it means you included the PEAR files the wrong way.
Try
include_once 'Mail.php';
include_once 'Mail/mime.php';

PHP will go through the include_path and try to find Mail.php as
./Mail.php
/usr/share/pear-php5/Mail.php
0
 
LVL 30

Author Comment

by:IanTh
ID: 24859813
noi still getting the warnings and then fatal error class 'mail_mime' not found
I don't think its installed as its a subdomain of a reseller account at fasthosts
I dont have shell access so I cannot install it
 
0
 
LVL 48

Expert Comment

by:hernst42
ID: 24859906
If you donÄt need to use the PEAR installation of your hoster.
Read COMPLETLY http://pear.php.net/manual/en/installation.shared.php special the second topic
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 30

Author Comment

by:IanTh
ID: 24898971
I dont think I can its a fasthost account and I found out pear is installed because I dit the following
<?php
require_once 'System.php';  
var_dump(class_exists('System'));
require_once 'PEAR.php';
var_dump(class_exists('PEAR'));

phpinfo ();
?>

And I get
bool(true) bool(true)
which means pear is installed
but I found out pear is installed with php
so I did

<?php
/* $path = "/usr/local/bin/pear";
set_include_path(get_include_path() . PATH_SEPARATOR . $path); */
require_once 'System.php';  
var_dump(class_exists('System'));
require_once 'PEAR.php';
var_dump(class_exists('PEAR'));
require_once 'Mail.php';
var_dump(class_exists('Mail'));
require_once 'Mail/mime.php';
var_dump(class_exists('mime'));
phpinfo ();
?>

and I get
bool(true) bool(true) bool(false) bool(false)
so how can I fix that
0
 
LVL 48

Expert Comment

by:hernst42
ID: 24899562
You can't fix this. PEAR is installed, but not Mail_Mime. You need to put those files/Classes via ssh/ftp/.. to the server in your own directory or use your own PEAR-instllation as descibed in the pear manual
0
 
LVL 30

Author Comment

by:IanTh
ID: 24902166
why though if pear is installed why do I get a fatal class error on Mail_mime
I have another sendmail script that uses mail() and that works on the server with no problem without include_once
so the path is correct. It just doesn't work with attachments as the fifth element in mail() is set by fasthost to be a username on their servers

mail($emailadd, $subject, $text, "From: $fromadd", "-f".$fromadd );
where normally it would be
mail($emailadd, $subject, $text, "From: $fromadd", $attachment );
0
 
LVL 48

Expert Comment

by:hernst42
ID: 24902654
Mail_mie is not part of the default pear installation and also has nothing to do with the php build in function mail. If you need attachemnt use
http://swiftmailer.sf.net or
http://phpmailer.sf.net
0
 
LVL 30

Accepted Solution

by:
IanTh earned 0 total points
ID: 24934722
fixed myself by getting rid of pear and using mail()
<?php
$fileatt = ''; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "test"; // Filename that will be used for the file as the attachment
$fromadd = 'ian@ian.no1net.co.uk'; // used for the fifth element in fasthost
$email_from = 'ian@gbpost.com'; // Who the email is from
$email_subject = "testing"; // The Subject of the email
$email_txt = "testing with attachment"; // Message that the email has in it

$email_to = $_POST['email address']; // Who the email is too

$headers = "From: ".$email_from;

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$email_message .= $email_txt;
// --------------------------Do not edit below this line--------------------------
$text = "<br>\nResults from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty. Click the back button to return to the form";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;

for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line<br>";
$text .= $conc;
$space = ' ';
}

$email_message .= $text;
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";


$ok = @mail($email_to, $email_subject, $email_message, $headers,"-f".$fromadd);

if($ok) {
echo "<font face=verdana size=2>The file was successfully sent!</font>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>
work brilliantly now
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Echo with auto submit 8 29
Delete  php pages of a part of our site 8 33
simple html dom php accessing table/cell  values 4 22
Ajax and PHP 4 31
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question