1

I'm looking for help with phpmailer. I use this script in php 5.5.12.

<?php
header ( 'Content-Type: text/html; charset=utf-8' );
require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';
$mail->ContentType = 'text/plain';
$mail->isHTML(false); 

$master = htmlspecialchars(trim($_POST['master']));
$name = htmlspecialchars(trim($_POST['name']));
$address = htmlspecialchars(trim($_POST['address']));
$telephone = htmlspecialchars(trim($_POST['telephone']));
$question = htmlspecialchars(trim($_POST['question'], " "));
$email = htmlspecialchars(trim($_POST['email']));

$mail->isSMTP();
$mail->Host = '/*here is my host name*/';
$mail->SMTPAuth = true;
$mail->Username = '/*here is my mail*/';
$mail->Password = '/*mypassword*/';
$mail->SMTPSecure = 'auto';
$mail->Port = '25';


$mail->From = 'example@mail.ru';
$mail->FromName = $name;
$mail->addAddress('receiver@gmail.com');

$mail->Subject = 'Subject';
$mail->Body    = "$master\n$name\n$address\n$telephone\n$email\n$question";
$dateposted = date("d.m.Y");

if(!$mail->send()) {
    echo 'Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent!';
    $content = "$master\n
$name\n
$address\n
$telephone\n
$email\n
$question";
    $fp = fopen($_SERVER['DOCUMENT_ROOT'] .'/meeting_email/' . "$dateposted" . "_" . $email . '.txt',"wb");
    fwrite($fp,$content);
    fclose($fp);
}

It works, but when i try to use it on my old server with php 4.3.4. i've got this error:

Fatal error: Cannot instantiate non-existent class: phpmailer in d:\sites\www\record_tech\sender.php on line 5 I red that PHPMailer does not support old php versions and i tryed to use PHPMailer 2.3.

I've replaced "require" to "require 'phpmailer1/class.phpmailer.php';"

because there was no PHPMailerAutoload, but i've got another error:

Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in d:\sites\www\record_tech\phpmailer1\class.phpmailer.php on line 45

Fatal error: Cannot instantiate non-existent class: phpmailer in d:\sites\www\record_tech\sender.php on line 5 I can't update this server to php 5 and have to resolve this problem on php4.

Dev
  • 13,492
  • 19
  • 81
  • 174
Eldar Blrs
  • 43
  • 7
  • 1
    4.3.4. is 13 years old - don't even think about using it –  Dec 29 '15 at 05:35
  • thank you for you comment, i said this to server owner, but there are a lot of very old projects, and nobody wants to use new technologies. That's why i am looking how to resolve this with old php – Eldar Blrs Dec 29 '15 at 05:50
  • 1
    if this is a client - walk away –  Dec 29 '15 at 05:52
  • Ditch PHPMailer and roll your own PHP4 mailing class - it's pretty easy. Furthermore - listen to everyone above me and exit this situation. You should not work for people that are using PHP4 in the year 2015. PHPMailer is written for PHP5 and PHP5 had giant leaps in how object orientated code works. PHP4 does not have the modern mechanisms for classes and objects. – Ryan Rentfro Dec 29 '15 at 06:17
  • thank you. I will tell server owner to update server, it is the better way to resolve this. – Eldar Blrs Dec 29 '15 at 06:43
  • I have another question, can i send mail on windows server 2003 without sendmail soft? Only with smtp config in php.ini – Eldar Blrs Dec 29 '15 at 09:56
  • Absolutely **do not** roll your own email class. You will do it wrong, guaranteed. Using PHP4 is certainly completely nuts (though it does have classes and objects), so you should definitely upgrade. If you really can't, you can always use an old version of PHPMailer - versions prior to 5.0 will also work on PHP 4 (all are tagged on github), but be aware that this means that it will be full of security holes, slow, and missing features, all fine if you really don't care about your server, your clients or their data... – Synchro Dec 29 '15 at 18:53

0 Answers0