FAQ
Edit report at https://pear.php.net/bugs/bug.php?id=19160&edit=1

ID: 19160
Updated by: alec@alec.pl
Reported By: ikonta at yandex dot ru
Summary: fail to send two different mails from single script
-Status: Open
+Status: Bogus
Type: Bug
Package: Mail
Operating System: Gentoo GNU/Linux
Package Version: 1.2.0
PHP Version: 5.3.8
Roadmap Versions:
New Comment:

-Status: Open
+Status: Bogus
Sorry, but your problem does not imply a bug in PEAR itself. For a
list of more appropriate places to ask for help using PEAR, please
visit http://pear.php.net/support/ as this bug system is not the
appropriate forum for asking support questions.

Thank you for your interest in PEAR.

Just replace include with include_once.


Previous Comments:
------------------------------------------------------------------------

[2011-12-28 08:10:35] imen

Description:
------------
I need the script to send several (usually two) different mails.
First generates and proceed normally, the second fails with error:
Fatal error: Cannot redeclare class Mail in /usr/share/php/Mail.php on
line 58

Test script:
---------------
I send mails via user-defined function:
<?php
function send_message() {
# emerge dev-php/PEAR-Mail
include('Mail.php');
# emerge dev-php/PEAR-Mail_Mime
include('Mail/mime.php');

$numargs = func_num_args();
$arg_list = func_get_args();
$eml_from = $arg_list[0];
$eml_to = $arg_list[1];
$eml_sub = $arg_list[2];
$eml_message_type = $arg_list[3];
$eml_message_text = $arg_list[4];

# $crlf = "\r\n";
$crlf = "\n";
$hdrs = array(
'From' => $eml_from,
'Subject' => $eml_sub
);
$build_args = array(
'head_charset' => 'koi8-r',
'head_encoding' => 'base64',
'text_charset' => 'koi8-r',
'text_encoding' => '8bit',
'html_charset' => 'koi8-r',
'html_encoding' => 'base64'
# 'text_encoding' => 'base64',
# 'text_encoding' => 'quoted-printable'
);

$mime = new Mail_mime($crlf);
if ($eml_message_type == "plain") {
$mime->setTXTBody($eml_message_text);
}
elseif ($eml_message_type == "html") {
$eml_message_html = "<html><body> $eml_message_text
</body></html>";
$mime->setHTMLBody($eml_message_html);
}
else {
exit("??????????? ?????? ???? ??????.");
}

if ($numargs == 6) {
$file_1 = $arg_list[5];
$mime->addAttachment($file_1, 'application/octet-stream');
# $mime->addAttachment($file_1, 'text/plain');
}
elseif ($numargs == 7) {
$file_1 = $arg_list[5];
$file_2 = $arg_list[6];
#
$mime->addAttachment($file_1, 'application/octet-stream');
# $mime->addAttachment($file_1, 'text/plain');
$mime->addAttachment($file_2, 'application/octet-stream');
# $mime->addAttachment($file_2, 'text/plain');
}
/* else {
exit("??????????? ????? ?????????? ??????? send_message");
} */

$body = $mime->get($build_args);
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send($eml_to, $hdrs, $body);

return 0;
}
?>

later invoked in the script.
for example:

<?php
$from_mailaddr = "smtp@mydomain.ru";
$recepient1_addr = "...";
...

send_message($from_mailaddr, $recepient1_addr, $email_subject, "plain",
$r1_mail_body, $file);

send_message($from_mailaddr, $recepient2_addr, $email_subject, "plain",
$r2_mail_body);

?>

Expected result:
----------------
Successfull creation and sending both (first, second and, if needed,
following mails).

Actual result:
--------------
Quoted fatal error while trying to redefine Mail class.

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedDec 28, '11 at 7:51a
activeDec 28, '11 at 7:51a
posts1
users1
websitepear.php.net

1 user in discussion

Alec: 1 post

People

Translate

site design / logo © 2022 Grokbase