usit Posted March 8, 2011 Share Posted March 8, 2011 Code transition from PHP4 to PHP5 My oop skills are weak – I need help converting an old version of PHPMailer to PHPMailer_v2.0.4. I assembled an on-line registration/mail script from open source codes and the resulting package has worked well for 8 or 9 years until some changes at my web host occurred. These led to my host switching my compiler, at my request, from PHP4 to PHP5. I then downloaded PHPMailer_v2.0.4 and tried to clean up the results, and am still trying. In the README that came with PHPMailer_v2.0.4 is this nice small script, by Andy Prevost, that I am using to replace the smtp mail section of my older code. The script, sans comments, is ... <?php require("class.phpmailer_v204.php"); //I added the ver. no. because several different ones exist out there. $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "smtp1.example.com;smtp2.example.com"; $mail->SMTPAuth = true; $mail->Username = "jswan"; $mail->Password = "secret"; $mail->From = "[email protected]"; $mail->FromName = "Mailer"; $mail->AddAddress("[email protected]", "Josh Adams"); $mail->AddAddress("[email protected]"); $mail->AddReplyTo("[email protected]", "Information"); $mail->WordWrap = 50; $mail->AddAttachment("/var/tmp/file.tar.gz"); $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); $mail->IsHTML(true); $mail->Subject = "Here is the subject"; $mail->Body = "This is the HTML message body <b>in bold!</b>"; $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo "Message has been sent"; ?> I naively assumed that it could be inserted into my script and proceeded to do so as follows ... //Mail freebies to requestors. foreach($options as $k => $value) //selected freebies { if($value){ $path_file = "$path" . $k . ".pdf"; if($mail) echo '$mailer = mailed <br>'; else echo '$mailer = not mailed <br>'; $mail->UseMSMailHeaders = true; $mail->IsSMTP(); $mail->Mailer = 'smtp'; //see www.phpfreaks.com/tutorials/130/6.ph //[NO LONGER VALID URL?] $mail->Priority = 3; $mail->Host = "[email protected]"; $mail->Hostname = "smtp.u-sit.net:25"; $mail->SMTPAuth = false; $mail->SMTPDebug = false; $mail->WordWrap = 70; $mail->IsHTML(); $mail->SMTPKeepAlive = true; $mail->From = "[email protected]"; $mail->FromName = "Ntelleck, LLC"; $mail->AddReplyTo ("[email protected]", "Feedback"); $mail->AddAttachment("$path_file", "$k", "base64", "application/pdf"); $mail->AddAddress("$to_email", "$to_name"); $mail->Subject = "File $k is attached; ID = $invoiceNo"; $mail->Body = "Newsletter back-issue bundles are posted individually because of large file sizes"; //$mail->ClearAttachments(); if(!$mail->Send()) { mail('[email protected]', "$k not sent: invoiceNo = $invoiceNo, Name: $last_name", "Mailer error: " . $mail->ErrorInfo); file_accesshttp:' } } // end of foreach However the compiler complains about two commands (so far that is, others probably await): $mail->IsSMTP(); and $mail->IsHTML(true); as shown here ... Fatal error: Call to undefined method stdClass::IsSMTP() I don’t understand the error ... ‘undefined method’ ... In the file class.phpmailer_v204.php, that is a required_once() file, require_once($_SERVER['DOCUMENT_ROOT'].'/lib/php/phpmailer/ class.phpmailer_v204.php'); is the definition, function IsSMTP() { $this->Mailer = 'smtp'; } Apparently I don’t know how to couple my specific parameter values into class.php_v204.php. Any help will be much appreciated. ens Link to comment https://forums.phpfreaks.com/topic/230011-code-transition-from-php4-to-php5/ Share on other sites More sharing options...
Krash Posted March 8, 2011 Share Posted March 8, 2011 You may be able to save yourself a lot of trouble if your host works like mine. I recently upgraded from php4 to 5, but have one regular user who has a problem running one of my scripts in php5. Host allows me to specify a version for specific scripts by appending the version number to the file suffix - filename.php4 will run in php4, even though the server is now running php5. Link to comment https://forums.phpfreaks.com/topic/230011-code-transition-from-php4-to-php5/#findComment-1184637 Share on other sites More sharing options...
usit Posted March 8, 2011 Author Share Posted March 8, 2011 Good idea Krash, but I fear that the road back to php4 is fraught with pot holes. A variety of changes were made to the original script with, I fear, incomplete documentation -- the foible of an autodidactic programmer. I will check your solution with my host. Then, if it can be implemented, and no other idea surfaces for using php5, I'll start on the road back. Thanks for your quick reply and neat idea. usit/ens Link to comment https://forums.phpfreaks.com/topic/230011-code-transition-from-php4-to-php5/#findComment-1184685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.