phpmailer stopped working Mailer Error: Fatal error: Uncaught Error: Class 'PHPMailer' not found - phpmailer

My mailer stopped working and I cant get it to work again. I downloaded the newest phpmailer 5.5 from githhub and recodeded the page . I used the examples to create my mailer and created my form and when I turned on error reporting I cant figure this error out. I looked at examples on ur site and the did not work i trued to use
Fatal error: Class 'PHPMailer' not found
my server is using PHP Version 7.3.15 with the corna virus this is essential for me to stay aflot can u help me???
<!DOCTYPE html>
<html lang="en" class="no-js">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<head>
<meta charset="utf-8">
<title>test | semndinbg mail</title>
<link rel="stylesheet" href="css/repairstatus.css" type="text/css" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<form id="form_1130906" class="appnitro" method="post" action="">
<div id="contact_slide1">
<div id="contact_name">FULL NAME: *<br>
<input id="element_4" name="name" class="element text medium" type="text" maxlength="50" value="" placeholder="FULL NAME"/></div>
<div id="contact_phone">PHONE NUMBER: *<br>
<input id="element_2_1" name="phone" class="element text" size="15" maxlength="15" value="" type="text" placeholder="PHONE NUMBER"></div>
</div> <!--contact_slide1-->
<div id="contact_slide2">
<div id="contact_email">VEHICLE MAKE: *<br>
<input id="element_1" name="email" class="element text medium" type="text" maxlength="40" value="" placeholder="Ex: FORD"/></div>
<div id="contact_contact">VEHICLE MODEL: *<br>
<input id="element_1" name="email" class="element text medium" type="text" maxlength="40" value="" placeholder="Ex: TAURUS"/></div>
</div> <!--contact_slide2-->
<div id="contact_message">MESSAGE:<br>
<textarea id="element_3" name="message" class="element textarea medium" placeholder="START TYPING MESAGE HERE..."></textarea></div>
<div id="contact_slide3">
<input id="saveForm" class="button_text" type="submit" name="submit" value="SEND" />
</div><!--contact_slide3-->
</form>
<?php
if (isset($_POST['submit'])){
//check if post form was submitted
if(isset($_POST)){
//check if hidden value was used
if(isset($_POST['miles']) && trim($_POST['miles']) !=''){
die('THERE WAS AN ERROR');
}
//implode all the post data and check against bad words in a text file
$my_bad_file = "inc/words.txt"; //make a new file and insert any bad items one per line, Phrases work as well
if(!file_exists($my_bad_file)){
die("Can't find $my_bad_file");
}
$check_content = implode(",", $_POST);
$bad_content_array = array_map('rtrim', file($my_bad_file));
foreach ($bad_content_array as $bad_content) {
$bad_content = strtolower($bad_content);
if (strpos(strtolower($check_content), $bad_content) !== false) {
die('THERE WAS A BAD ERROR');
}}
}
echo "Mailer Error:" . $mail->ErrorInfo;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require("inc/PHPMailer2/src/PHPMailer.php");
require("inc/PHPMailer2/src/SMTP.php");
$mail = new PHPMailer/PHPMailer/PHPMailer();
$mail->IsSMTP(); // enable SMTP
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// SMTP::DEBUG_OFF = off (for production use)
// SMTP::DEBUG_CLIENT = client messages
// SMTP::DEBUG_SERVER = client and server messages
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption mechanism to use - STARTTLS or SMTPS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = 'test#gmail.com';
//Password to use for SMTP authentication
$mail->Password = 'aaaa1111';
//Set who the message is to be sent from
$mail->setFrom('from#example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto#example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
$mail->AddAddress('test#test.com');
$mail->Priority = 1;
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "FINE LINE AUTO BODY | Repair Status";
$mail->AltBody = "This is the text-only body";
$name = isset($_POST['name']) ? $_POST['name'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
$make = isset($_POST['make']) ? $_POST['make'] : '';
$model = isset($_POST['model']) ? $_POST['model'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
// gets info from form
$name = $_POST['name'] ;
$phone = $_POST['phone'] ;
$make = $_POST['make'] ;
$model = $_POST['model'] ;
$message = $_POST['message'] ;
$ip = $_SERVER["REMOTE_HOST"] ?: gethostbyaddr($_SERVER["REMOTE_ADDR"]);
// defines how message looks in email
$mail->Body="
<html>
<head>
</head>
<body>
<center>
<span style='color:red;'>This is from a customer, We are repairing his vehicle. Lets not keep them waiting!</span>
<div style='width:750px;text-align:center;'>
<div style='float:;'>
<span style='font-size:px;'><b>Personal Info</b><br></span>
<br>
<span style='font-size:px;'>---------------<br></span>
<br>
<span style='font-size:px;'>Full Name: $name<br></span>
<br>
<span style='font-size:px;'>Phone Number: $phone<br></span>
<br>
<span style='font-size:px;'>Vehicle Make: $make<br></span>
<br>
<span style='font-size:px;'>Vehicle Model: $model<br></span>
<br>
<span style='font-size:px;'>Message: $message<br></span>
</div></div>
</center>
</body>
</html>
";
// looks good in your inbox
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error:" . $mail->ErrorInfo;
} else {
echo '<meta http-equiv="refresh" content="0;url=https://www.sucess.com/">';
}}
?>
</body>
</html>

You're doing the same thing twice, but incorrectly (and unnecessarily) the second time.
This method of creating an instance is correct for PHPMailer 6.0 and later (though you can make it look better by using an alias). Note the direction of the slashes:
$mail = new PHPMailer\PHPMailer\PHPMailer();
This is the same as saying:
use PHPMailer\PHPMailer\PHPMailer;
...
$mail = new PHPMailer();
Later in your code, you're doing this (without having an earlier use statement):
$mail = new PHPMailer;
This won't work unless you either declare the PHPMailer namespace, or import the namespaced class name into your own namespace. Regardless – this is a duplicate and you can simply delete this line.
You might want to read the upgrade guide provided with PHPMailer.

Related

Showing Error Message

When I run this program and enter Dan Dan inside of it, it works. Now when I enter http://sftpgamblerlotteryclub/www it doesn't work. I would like for it to catch the sftp, /, www and return back to the form and inform the user " this is not a username, please resubmit". Thanks you.
<?php
// define variables and set to empty values
$nameErr = $emailErr = "";
$name = $email = $subject = "";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (preg_match("/^[a-zA-Z-']*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Contact Form</title>
</head>
<body>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name:
<input type="text" name="name">
<span class="error">* <?php echo $nameErr; ?> </span>
<br><br>
<input name="submit_btn" type="submit" id="submit-btn" value="Send Mail">
</form>
</div>
</body>
</html>
<?php
echo $name;
?>
Your test_input function is striping out the / so that is removed before you do your preg_match. As such you will never catch the /.
If I understand your question you want to make sure the user name is not in a list of prohibited names. For that I would create an array of prohibited names and then do a stripos on the json_encoded output of the array within a if condition. This makes it easy to expand the list of prohibited names.
This is based on your code snip-it.
$array = ["sftp", "http", "www"];
if (stripos(json_encode($array),$name) !== false) {
$nameErr = "This is not a valid user name"
}

phpMailer not sending emails with no errors

I'm having this issue regarding sending emails using phpMailer
My code is
public function sendEmailNovoUtilizador($nome, $email){
$mail = new PHPMailer;
$mail->SMTPDebug = 1;
$mail->isSMTP();
$mail->Host = 'xxxxx.xxxxxxx.pt';
$mail->SMTPAuth = true;
$mail->Username = 'xxxxxxx#xxxxxx.edu.pt';
$mail->Password = 'xxxxxxx';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('xxxxxxx#xxxxxx.edu.pt', 'Diretor');
$mail->addAddress($email, 'Novo utilizador');
$mail->IsHTML(true);
$mail->Subject = 'Registo de um novo utilizador';
$mail->CharSet = 'UTF-8';
$mail->Body = "
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
</head>
<body>
<h1>Novo Utilizador</h1>
<p>Seguem os seus dados</p>
<table>
<tbody>
<tr>
<td><strong>Nome:</strong></td>
<td>$nome</td>
</tr>
<tr>
<td><strong>Email:</strong></td>
<td>$email</td>
</tr>
</tbody>
</table>
<p> </p>
<p>Aguarde a validação por parte do Diretor</p>
<p> </p>
<p>Equipa ESMAIOR.</p>
<p> </p>
<p>Obrigado</p>
</body>
</html>";
$mail->addAttachment('../img/logo_pdf.jpg');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
Error i get when i log into my server
Delivery Event Details
Event: failure
User: ebspma
Domain: xxxx.edu.pt
Sender: xxxxxx#xxxx.edu.pt
Sent Time: Sep 2, 2016 10:56:22 PM
Sender Host: xxxxxx.edu.pt
Sender IP: 109.71.40.19
Authentication: dovecot_login
Spam Score: 0
Recipient: xxxxxxx#gmail.com
Delivery User:
Delivery
Domain:
Delivered To:
Router: smarthost_cleanmx_regular
Transport: remote_smtp_cleanmx_smart_regular
Out Time: Sep 2, 2016 10:56:22 PM
ID: 1bfwS2­002VOU­Q4
Delivery Host: smtp.cleanmx.pt
Delivery IP: 130.185.80.200
Size: 6.52 KB
Result:
DHE­RSA­AES256­SHA:256 CV=yes DN="/OU=Domain Control
Validated/CN=*.cleanmx.pt": SMTP error from remote mail server after MAIL FROM:
<xxxxxx#xxxxx.edu.pt> SIZE=7818: 550­ Verification failed for
<xxxxxx#xxxx.edu.pt>\n550­Previous (
What's wrong, it seems it connect but can't delivery? This is what i get from my server log in email delivery

PasswordReset is not working in WebMatrix

I am using the exsisting PasswordReset form in WebMatrix. I didn't change anything in the module but, it's not working. When I click the "Did you forget your password?" link and it takes me to the ForgotPassword form. After I enter my email address and click 'Send Instructions' it goes to my email. But, when I click on the link it provides I immediately get the Password Reset screen but, he top of the screen says, "Could not reset password. Please correct the errors and try again." Eventhough, I try resetting my password anyway nothing happens.
Below is the Password Reset code:
#* Remove this section if you are using bundling *#
#section Scripts {
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
}
#{
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Password Reset";
var passwordResetToken = Request.Form["resetToken"] ?? Request.QueryString["resetToken"];
bool tokenExpired = false;
bool isSuccess = false;
// Setup validation
Validation.RequireField("newPassword", "The new password field is required.");
Validation.Add("confirmPassword",
Validator.EqualsTo("newPassword", "The new password and confirmation password do not match."));
Validation.RequireField("passwordResetToken", "The password reset token field is required.");
Validation.Add("newPassword",
Validator.StringLength(
maxLength: Int32.MaxValue,
minLength: 6,
errorMessage: "New password must be at least 6 characters"));
if (IsPost && Validation.IsValid()) {
AntiForgery.Validate();
var newPassword = Request["newPassword"];
var confirmPassword = Request["confirmPassword"];
if (WebSecurity.ResetPassword(passwordResetToken, newPassword)) {
isSuccess = true;
} else {
ModelState.AddError("passwordResetToken", "The password reset token is invalid.");
tokenExpired = true;
}
}
}
<hgroup class="title">
<h1>#Page.Title.</h1>
<h2>Use the form below to reset your password.</h2>
</hgroup>
#if (!WebMail.SmtpServer.IsEmpty()) {
if (!Validation.IsValid()) {
<p class="validation-summary-errors">
#if (tokenExpired) {
<text>The password reset token is incorrect or may be expired. Visit the forgot password page
to generate a new one.</text>
} else {
<text>Could not reset password. Please correct the errors and try again.</text>
}
</p>
}
if (isSuccess) {
<p class="message-success">
Password changed! Click here to log in.
</p>
}
<form method="post">
#AntiForgery.GetHtml()
<fieldset>
<legend>Password Change Form</legend>
<ol>
<li class="new-password">
<label for="newPassword" #if (!ModelState.IsValidField("newPassword")) {<text>class="error-label"</text>}>New password</label>
<input type="password" id="newPassword" name="newPassword" disabled="#isSuccess" #Validation.For("newPassword") />
#Html.ValidationMessage("newPassword")
</li>
<li class="confirm-password">
<label for="confirmPassword" #if (!ModelState.IsValidField("confirmPassword")) {<text>class="error-label"</text>}>Confirm password</label>
<input type="password" id="confirmPassword" name="confirmPassword" disabled="#isSuccess" #Validation.For("confirmPassword") />
#Html.ValidationMessage("confirmPassword")
</li>
<li class="reset-token">
<label for="resetToken" #if (!ModelState.IsValidField("resetToken")) {<text>class="error-label"</text>}>Password reset token</label>
<input type="text" id="resetToken" name="resetToken" value="#passwordResetToken" disabled="#isSuccess" #Validation.For("resetToken") />
#Html.ValidationMessage("resetToken")
</li>
</ol>
<input type="submit" value="Reset password" disabled="#isSuccess"/>
</fieldset>
</form>
} else {
<p class="message-info">
Password recovery is disabled for this website because the SMTP server is
not configured correctly. Please contact the owner of this site to reset
your password.
</p>
}
Here is the code in my _AppStart:
WebSecurity.InitializeDatabaseConnection("StarterSite", "UserProfile", "UserId", "Email", autoCreateTables: true);
OAuthWebSecurity.RegisterGoogleClient();
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.EnableSsl = true;
WebMail.SmtpPort = 587;
WebMail.UserName = "mark.anthnony#yahoo.com";
WebMail.Password = "September";
WebMail.From = "mark.anthony#yahoo.com";
Change constancies in your User object. Delete required attributes from there. Also. I suggest to write your own base authentication.

How to upload images in jaggeryjs?

This is my sample HTML code
<html>
<head>
<title>
fileupload
</title>
</head>
<body>
<form action="process.jag" method="post" id="" name="">
<!-- File input filed -->
<input type="file" name="myFile">
<!-- The submit button. It calls the server side function uploadfiles() on click -->
<input type="submit" id="" value="Upload File">
</form>
</body>
</html>
This is my jaggery code
<%
var verb=request.getMethod();
if (verb=='POST'){
var log = new Log();
var file = request.getFile("myFile");
file.move("C:\Users\vatsal ramesh gosar\Desktop\New folder\form\fileUploadUsingJaggery"+file.getName());
response.sendRedirect("https://www.google.com");
}
%>
It is giving a NULL Pointer Exception.
Please help me solve this problem with an efficient code.
request.getFile("myFile") does not represent a physical file, rather it represent a stream to the uploaded file. Hence you cannot "move" it using file.move("/moving/path") function. If you want to save the uploaded file, then use the following code snippet.
var uploadedFile = request.getFile("myFile");
var savedFile = new File("/path/to/save/location/" + uploadedFile.getName());
savedFile.open('w');
savedFile.write(uploadedFile.getStream());
savedFile.close();
In Jaggery documentation I haven't find any way to upload image into the server. But some alternatives there...
You encode the image into base64 encoding, you may use this way too encode the images on base64
$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
then send the encoded String using POST request using Jaggery.

Custom search using doctrine and symfony2

I want to create a searchController, that searches the db for whatever keywords the user enters into a textbox. I have looked at this article and this and many more.
This is what I have so far:
public function searchAction(Request $request) {
if ($request->getMEthod() == 'GET') {
$title = $request->get('Search_term');
//echo "<div class=\"searchText\">Search Results</div><hr/>";
$em = $this->getDoctrine()->getManager();
$Search_terms = explode(' ', $title); //splits search terms at spaces
$query = "SELECT * FROM Entity/Adverts WHERE ";
foreach ($Search_terms as $each) {
// echo $each."<br/>";
$i = 0;
$i++;
if ($i == 1)
$query .= "Adv_title LIKE '%$each%' ";
else
$query .= "OR Adv_title LIKE '%$each%' ";
}
$query = $em->createQuery($query);
$numRow = $query->count();
if ($numRow > 0) {
while ($query->fetch()) {
$repository = $em->getRepository('YCRYcrBundle:Adverts')->findBy(array(
'advTitle' => $title
));
/* echo "<h2><a href='#'> $title</a> </h2>";
echo "$desc <br /> <br />";
echo"<a href='/201308/View/YCR/index.php' class='link-button right'><span>Apply</span></a>"; */
}
}
/* else
echo "none found for \"<b>$SearchTerm </b>\"</br>Check spelling"; */
}
return $this->render('YCRYcrBundle:Search:search.html.twig', array('title' => $title->getAdvTitle()));
}
What is missing from this code to make it work, and or what is wrong?
Edit:
sorry of I was unclear. I am getting the following error:
FatalErrorException: Error: Call to undefined method Doctrine\ORM\Query::count() in C:\wamp\www\201308\src\YCR\YcrBundle\Controller\SearchController.php line 28
and do not know what is wrong as I am new to Symfony and doctrine.
This is what I have in my search.html.twig:
{% extends "YCRYcrBundle::layout.html.twig" %}
{% block content %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>YCR Job Search</title>
<link href="stylesheets/style.css" rel="stylesheet" type="text/css" />
<link href="stylesheets/colour.css" rel="stylesheet" type="text/css" />
</head>
<body onload="b = setInterval('clear()', 0);">
<div class="topDiv">
<div style="float: left;">
<img src="/201308/View/images/ycr.jpg" alt="ycr"></div>
<br/>
<!--<H2>Search for a Job</H2>-->
<div class="searchform">
<form id="formsearch" name="p" method="get" action="index.php">
<span>
<input name="Search_term" class="editbox_search" id="editbox_search" maxlength="80" value="<?php $this; ?>" type="text" />
</span>
<input type="image" name="button_search" src="images/search.gif" class="button_search" alt="" />
</form>
<br/>
<div id="search_results">
</div>
</div>
<!-- </div>-->
<script type="text/javascript" src="http://code.jquery.com/jquery- 1.7.2.min.js"></script><!--javascript jquery library-->
<script type="text/javascript" src="../View/scripts/Script.js"></script>
{% endblock %}
When the user searches, for example programmer, to display like this:
-Programmer
-a summary of the description of what a programmer entails
-a button/link that reads: read more, that takes me to a page with full description
You are pretty far off the mark. Query has no count function, that's a querybuilder function. You may write raw sql, but you are better served learning querybuilder : http://docs.doctrine-project.org/en/latest/reference/query-builder.html. Remember, doctrine is designed to give you a list of entities, that you pass to the twig to do stuff with.
Also, your twig won't do much, see the basics of usage in the very crude twig I've included. use {{entity.method}} or {{entity.field}} to get the various display properties of each entity. Use a twig foreach to loop through them all. Take a look at my example in your context, and then go read the twig documents to fill in the gaps. http://twig.sensiolabs.org/documentation
The Controller
public function searchAction(Request $request) {
if ($request->getMethod() == 'GET') {
$title = $request->get('Search_term');
$em = $this->getDoctrine()->getManager();
$qb = $em->getRepository('YCRYcrBundle:Adverts')
->createQueryBuilder('a');
$searches= explode(' ', $title);
foreach ($searches as $sk => $sv) {
$cqb[]=$qb->expr()->like("CONCAT($sv, '')", "'%$sv%'");
}
$qb->andWhere(call_user_func_array(array($qb->expr(),"orx"),$cqb));
$adverts = $qb->getResult();
}
return $this->render('YCRYcrBundle:Search:search.html.twig'
, array('adverts' => $adverts));
}
And a twig file
{# Your other stuff #}
{% for advert in adverts %}
{{advert.getId}}
{# call the various method and fields for your display#}
{% endfor %}
you need to execute the query (with execute ) or you wont get an array. and you should be using the query builder instead DQL string concatenation. Read the doctrine doc on basic doctrine usage , the entity namespace seems to be incorrect too.
i quote you :
$query = $em->createQuery($query);
$numRow = $query->count();
should be at least :
$query = $em->createQuery($query);
$numRow = count($query->execute())
edit : not sure wether you would be getting an array or an ArrayCollection , check if the count fonction works on the ArrayCollection.

Resources