Guys, i dont understand where did i do wrong, im trying to send an email when a checkbox is checked? Please help!
require_once('../PHPmailer/PHPMailerAutoload.php');
if(isset($_POST['checked'])){
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth();
$mail->SMTPSecure = 'ssl';
$mail->Host ='smtp.gmail.com';
$mail->Port ='587';
$mail->isHTML();
$mail->Username ='@gmail.com';
$mail->Password ='';
$mail->SetForm('no-reply@*.com');
$mail->Subject = 'Hello there!';
$mail->Body = 'Thank you for being part of us.';
$mail->AddAddress($email);
$mail->Send();
}
The error "Call to undefined method PHPMailer::SMTPAuth()" spells it out that there is no method with that name, $mail->SMTPAuth() will never work because SMTPAuth() does not exist.
However, you can set the value of SMTPAuth with the code $mail->SMTPAuth = true;
Look at the README, especially the example.
Thank you @NiklasBr thats a speedy reply as im very appreaciated but after i changed it, it gave me this error
Fatal error: Can't use method return value in write context
That sounds like you have a very old version of PHP, can you tell us which version of PHPMailer and PHP you are using?
my current php version is 7.2.28 and php mailer version is 6.1.5
You just updated - the first line of your code indicated you were using an old 5.2 version before.
That error means what it says - you're trying to assign a value to something that you can't assign a value to, like a function. I suspect you're doing this:
$mail->SMTPAuth() = true;
instead of:
$mail->SMTPAuth = true;
You're also doing this:
$mail->SMTPSecure = 'ssl';
$mail->Port ='587';
That's wrong in two ways: Port is an integer, not a string, and you can't use sslmode on port 587. Either change Port to 465, or SMTPSecure to tls, not both!
Overall, you'd be best off doing what Niklas said and starting again using known-good code rather than making random changes and wondering why it doesn't work.
Deeply apologized! It was my mistake and what @NiklasBr provided me the solution was correct indeed which was this $mail->SMTPAuth = true; which has troubling me the whole time but i assigned the boolean to """$mail->isSMTP()= true;""" which doesnt make sense at all. Until i read @Synchro your comment carefully i was able to traced back my mistake easily, also i did changed my port as you mentioned which it was a complete mess before that, and yes i was using the old version of PHP mailer which is v5.2. Thank you for both of your time it did solved my problem! Deeply appreciated it!
Most helpful comment
You just updated - the first line of your code indicated you were using an old 5.2 version before.
That error means what it says - you're trying to assign a value to something that you can't assign a value to, like a function. I suspect you're doing this:
instead of:
You're also doing this:
That's wrong in two ways:
Portis an integer, not a string, and you can't usesslmode on port 587. Either changePortto 465, orSMTPSecuretotls, not both!Overall, you'd be best off doing what Niklas said and starting again using known-good code rather than making random changes and wondering why it doesn't work.