Jump to content


Photo

Fatal error: Call to undefined method PHPMailer::Subject() in .......


Best Answer jazzman1, 27 February 2014 - 07:53 PM

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
Go to the full post


  • Please log in to reply
14 replies to this topic

#1 rocky48

rocky48

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationHastings, UK
  • Age:66

Posted 21 February 2014 - 07:34 AM

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?
Rocky48

#2 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,611 posts

Posted 21 February 2014 - 08:51 AM

the subject isn't a method, its a property.


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#3 rocky48

rocky48

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationHastings, UK
  • Age:66

Posted 21 February 2014 - 02:20 PM

So what is the method?

 

I am a relantive newbie, so I don't understand!


Rocky48

#4 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 21 February 2014 - 03:54 PM

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)) {

} 


#5 rocky48

rocky48

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationHastings, UK
  • Age:66

Posted 23 February 2014 - 05:54 AM

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?


Rocky48

#6 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 23 February 2014 - 08:41 AM

$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.



#7 rocky48

rocky48

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationHastings, UK
  • Age:66

Posted 23 February 2014 - 11:11 AM

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?


Rocky48

#8 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 23 February 2014 - 11:38 AM

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 by jazzman1, 23 February 2014 - 11:39 AM.


#9 rocky48

rocky48

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationHastings, UK
  • Age:66

Posted 25 February 2014 - 07:20 AM

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!


Rocky48

#10 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 25 February 2014 - 08:16 AM

 

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.



#11 rocky48

rocky48

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationHastings, UK
  • Age:66

Posted 27 February 2014 - 11:32 AM

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 by rocky48, 27 February 2014 - 11:35 AM.

Rocky48

#12 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 27 February 2014 - 12:39 PM

Is it allowed for users to subscribe to your site with empty email? Is it allowed they to have more than 1 email?



#13 rocky48

rocky48

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationHastings, UK
  • Age:66

Posted 27 February 2014 - 01:36 PM

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 by rocky48, 27 February 2014 - 01:38 PM.

Rocky48

#14 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 27 February 2014 - 07:53 PM   Best Answer

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


#15 rocky48

rocky48

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts
  • LocationHastings, UK
  • Age:66

Posted 12 March 2014 - 01:41 PM

Hi Jazzman

 

Great this worked when I corrected the error $rowm to $row.

 

Many thanks!


Rocky48




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com