Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team

I need some help, i opened up my cmd and run this command on the terminal and executed fine composer require phpmailer/phpmailer. The went to the subdirectory to copied these files over to the server(c-panel). Now the server is complaining its not finding them, yet the order of them from the server its correct, but the logs says this message "
Fatal error:  require(): Failed opening required 'phpmailer/class.phpmailer.php'
"

What I have tried:

<?php
require('phpmailer/class.phpmailer.php');
require '../vendor/phpmailer/phpmailer/autoload.php';

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;  
$mail->Port     = 587;  
$mail->Username = "ggcobani@gmail.com";
$mail->Password = "861026@Metro";
$mail->Host     = "smtp.gmail.com";
$mail->Mailer   = "smtp";
$mail->SetFrom($_POST["userEmail"], $_POST["userName"]);
$mail->AddReplyTo($_POST["userEmail"], $_POST["userName"]);
$mail->AddAddress("RECIPIENT_EMAIL");	
$mail->Subject = $_POST["subject"];
$mail->WordWrap   = 80;
$mail->MsgHTML($_POST["content"]);

$mail->Body = $mail_body;

// sending multiple attachment

$fileNameArray = array($file1Name, $file2Name, $file3Name);
$filePathArray = array($file1Path, $file2Path, file3Path);
//  . . .
for($i = 0; $i < 3; $i++) {
	$mail->addAttachment($fileDataArray[$i], $fileNameArray[$i]);
}

$mail->Send();
$mail->IsHTML(true);

if(!$mail->Send()) {
	echo "<p class='error'>Problem in Sending Mail.</p>";
} else {
	echo "<p class='success'>Mail Sent Successfully.</p>";
}	
?>
Posted
Comments
Richard MacCutchan 7-Mar-23 3:47am    
The file is definitely not in the place that the server is searching. So check again the exact location relative to where this file is stored.
Gcobani Mkontwana 7-Mar-23 4:40am    
@Richard MacCutchan funny part on the server its sitting on this directory PHPMailer\PHPMailerAutoload.php
PHPMailer\vendor
PHPMailer\class.phpmailer.php
Gcobani Mkontwana 7-Mar-23 4:42am    
@Richard MacCutchan, i tried to use this require_once 'PHPMailer/PHPMailerAutoload.php';
use PHPMailer;
but now im getting from the logs PHP Fatal error: Uncaught Error: Call to undefined method PHPMailer::setFrom()
Richard MacCutchan 7-Mar-23 6:46am    
$mail->SetFrom($_POST["userEmail"], $_POST["userName"]);

The method name is setFrom with a lower case 's'.

I suggest you check the documentation for the correct spelling of all the method calls.

Also if you wish to reply to a comment then please use the Reply button above the message. Just adding comments does not let me know that you have replied.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900