rocky48 Posted February 21, 2014 Share Posted February 21, 2014 I am getting the error shown in the title but can't see why it is erroring! Here is the code: < <html> <head> <title>PHPMailer - MySQL Database - SMTP basic test with authentication</title> </head> <body> <?php print_r($_POST); //echo $_POST['Message']; //echo $_POST['Attachment1']; //echo $_POST['Subject']; //error_reporting(E_ALL); //error_reporting(E_STRICT); date_default_timezone_set('Europe/London'); require_once('\class.phpmailer.php'); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); //$body = $_POST['Message']; //$attachment = $_POST['Attachment1']; //echo $body; //echo $attachment; $mail->SetFrom('webmaster@1066cards4u.co.uk', 'List manager'); $mail->AddReplyTo('webmaster@1066cards4u.co.uk', 'List manager'); //$mail->Subject = ($_POST['Subject']); include('connect_mailer.php'); doDB5(); echo "connected to database? \n"; if (mysqli_connect_errno()) { //if connection fails, stop script execution printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { //otherwise, get emails from subscribers list $sql = "SELECT email FROM subscribers"; $result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli)); //create a From: mailheader $mailheaders = "From: webmaster@1066cards4u.co.uk>"; //loop through results and send mail while ($row = mysqli_fetch_array($result)) { //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->AddAddress($row['email']); $mail->SetFrom('administrator@1066cards4u.co.uk', 'Tony Hudson'); } $sqlmail = "SELECT subtxt, message, attachment FROM mail_info WHERE EID= '".$_POST['Eno']."'"; $mailresult = mysqli_query($mysqli, $sqlmail) or die(mysqli_error($mysqli)); while ($rowm = mysqli_fetch_array($mailresult)) { $mail->Subject($rowm['subtxt']); $mail->MsgHTML($rowm['message']); $mail->AddAttachment($rowm['attachment']); // attachment } if(!$mail->Send()) { echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Messages sent!'; } // Clear all addresses and attachments for next loop $mail->ClearAddresses(); $mail->ClearAttachments(); } ?> </body> </html> > Anyone familiar with PHPmailer? Please help? Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/ Share on other sites More sharing options...
mac_gyver Posted February 21, 2014 Share Posted February 21, 2014 the subject isn't a method, its a property. Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1469869 Share on other sites More sharing options...
rocky48 Posted February 21, 2014 Author Share Posted February 21, 2014 So what is the method? I am a relantive newbie, so I don't understand! Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1469897 Share on other sites More sharing options...
jazzman1 Posted February 21, 2014 Share Posted February 21, 2014 So what is the method? I am a relantive newbie, so I don't understand! According mailer's docs the subject is a property as @mac said above. $mail->Subject = "PHPMailer Test Subject via mail(), basic"; $mail->Subject // property $mail->Subject () // method How many rows of data do you expect to retrieve, based on $_POST['Eno'] by using the following-> $sqlmail = "SELECT subtxt, message, attachment FROM mail_info WHERE EID= '".$_POST['Eno']."'"; while ($rowm = mysqli_fetch_array($mailresult)) { } Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1469902 Share on other sites More sharing options...
rocky48 Posted February 23, 2014 Author Share Posted February 23, 2014 Hi Jazzman I have 2 tables in my database: one where i will store the mail list subscribers and the other wich will store the message details (Subject, Message body and attachment). I felt that this was the best way of getting the script to send the latest message. Looking at my script and going on what you have said, surely $mail->Subject (rowm[subtxt]); is a method? So why is it failing? Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1470226 Share on other sites More sharing options...
jazzman1 Posted February 23, 2014 Share Posted February 23, 2014 $mail->Subject (rowm[subtxt]) is a method! Try, $mail->Subject = rowm[subtxt]; So why is it failing? Because you're trying to call a method named "Subject", but actually it doesn't exist in your library and the php parser returns fatal error message. Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1470246 Share on other sites More sharing options...
rocky48 Posted February 23, 2014 Author Share Posted February 23, 2014 Hi Jazzman Tried your suggestion: No error, but email still does not have subject line! Looked at another example and saw that it should have had an equals after "Subject", there it had a string inside single quotes. The problem appears to be with the way I am writing the instruction to extract the field from the array. I am not sure of the correct syntax so are you able to help? Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1470267 Share on other sites More sharing options...
jazzman1 Posted February 23, 2014 Share Posted February 23, 2014 (edited) Unfortunately, I'm not using phpmailer to provide an efficacious help. However, it leads me to believe that you haven't returned any rows from database. It's a bad practice also to send two different sql select statements using looping application's constructs to return data from 2 or more tables and columns. Use "JOIN" instead! Do "DESCRIBE" to provide information about those 2 tables and their columns. Edited February 23, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1470277 Share on other sites More sharing options...
rocky48 Posted February 25, 2014 Author Share Posted February 25, 2014 Hi Jazzman Firstly it is returning the other fields from the database table, but not the Subject field. I have found the error! A silly one the 'subtxt' should have been 'Subtxt'. Regarding the database question, if I write it as one MySQL statement, because of the fact I am using a where statement in the mail_info table, what effect will it have on the subscribers table? I other words will it loop through all the subscribers? Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1470593 Share on other sites More sharing options...
jazzman1 Posted February 25, 2014 Share Posted February 25, 2014 Regarding the database question, if I write it as one MySQL statement, because of the fact I am using a where statement in the mail_info table, what effect will it have on the subscribers table? I other words will it loop through all the subscribers? Yes, everything will be the same except the performance. However, to provide a "JOIN" help, we need to know the structure of "subscribers" and "mail_info" tables. Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1470600 Share on other sites More sharing options...
rocky48 Posted February 27, 2014 Author Share Posted February 27, 2014 (edited) Hi Jazzman Here is the structure of the 2 tables: subscribers Field Type Null Default id int(11) Yes NULL email varchar(150) Yes NULL Forename varchar(50) Yes NULL Surname varchar(50) Yes NULL Country varchar(50) Yes NULL Gender text Yes NULL Indexes: Keyname Type Cardinality Field PRIMARY PRIMARY 4 id mail_info Field Type Null Default EID int(11) Yes NULL subtxt text Yes NULL message longtext Yes NULL attachment text Yes NULL Indexes: Keyname Type Cardinality Field PRIMARY PRIMARY 0 EID Your help is appreciated! Edited February 27, 2014 by rocky48 Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1470921 Share on other sites More sharing options...
jazzman1 Posted February 27, 2014 Share Posted February 27, 2014 Is it allowed for users to subscribe to your site with empty email? Is it allowed they to have more than 1 email? Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1470932 Share on other sites More sharing options...
rocky48 Posted February 27, 2014 Author Share Posted February 27, 2014 (edited) Hi Jazzman As it checks the email to see if it exists I guess that the answer is no, but I can't test this as I am in the middle of trying to add reCaptcha working. The answer to qu. 2 is yes. At the moment I am getting tied up in knots to make reCaptcha work. As the form and the code to add the values to the are in the same file I am finding it difficult to get my form to be displayed. The reCaptcha works OK, its dovetailing it into my code is the difficulty. However that is another question. I have posted a different thread on this subject > (Since adding reCaptcha code not working) Edited February 27, 2014 by rocky48 Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1470946 Share on other sites More sharing options...
jazzman1 Posted February 28, 2014 Share Posted February 28, 2014 Then, no need to use a "JOIN" as I thought before, because there is no relationship between them. All you need to do is select the results of those two tables combaining them in one query. // instead //otherwise, get emails from subscribers list $sql = "SELECT email FROM subscribers"; $result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli)); //create a From: mailheader $mailheaders = "From: webmaster@1066cards4u.co.uk>"; //loop through results and send mail while ($row = mysqli_fetch_array($result)) { //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->AddAddress($row['email']); $mail->SetFrom('administrator@1066cards4u.co.uk', 'Tony Hudson'); } $sqlmail = "SELECT subtxt, message, attachment FROM mail_info WHERE EID= '".$_POST['Eno']."'"; $mailresult = mysqli_query($mysqli, $sqlmail) or die(mysqli_error($mysqli)); while ($rowm = mysqli_fetch_array($mailresult)) { $mail->Subject($rowm['subtxt']); $mail->MsgHTML($rowm['message']); $mail->AddAttachment($rowm['attachment']); // attachment // to be //otherwise, get emails from subscribers list $eno = intval($_POST['Eno']); $sql = "SELECT s.email, m.subtxt, m.message, m.attachment FROM subscribers s, mail_info m WHERE EID = $eno"; $result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli)); //create a From: mailheader $mailheaders = "From: webmaster@1066cards4u.co.uk>"; //loop through results and send mail while ($row = mysqli_fetch_array($result)) { //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->AddAddress($row['email']); $mail->SetFrom('administrator@1066cards4u.co.uk', 'Tony Hudson'); $mail->Subject = $row['subtxt']; $mail->MsgHTML($rowm['message']); $mail->AddAttachment($rowm['attachment']); // attachment Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1471002 Share on other sites More sharing options...
rocky48 Posted March 12, 2014 Author Share Posted March 12, 2014 Hi Jazzman Great this worked when I corrected the error $rowm to $row. Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/286375-fatal-error-call-to-undefined-method-phpmailersubject-in/#findComment-1472348 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.