Phpmailer is not working in the site

PHP mailer, it is a class library for PHP which provides a set of functions for building and sending mail,It support mail sending in several ways like mail(), Sendmail, qmail & direct to SMTP servers( you can also SMTP base functions)PHPMailer is an easy and efficient way of sending mail with PHP.   

What is the Issue?

The website is having a contact form when the user enters the details and proceed further by submitting it which will send the success message to the users but its showing blank page with no error message and even no mail is received. We receive this issue from our registered Clients who have hosted their website on our VPS and Cloud Server, ensure that the MX record your domain is pointing to HostingRaja, you check the MX record for your domain using the below link :

https://mxtoolbox.com/

If the MX Record is not pointing to HostingRaja then you will have to update your MX records.

If the MX record is pointing to HostingRaja then proceed to the next step.

Web Hosting
Web Hosting
at a very Affordable Price
Starts at Rs. 69
VPS Hosting
VPS Hosting
Customized for all technologies
Starts at Rs. 732
Cloud Hosting
Cloud Hosting
Security & Performance Guaranteed
Starts at Rs. 2680
Windows Hosting
Windows Hosting
Reliable Windows Web Hosting
Starts at Rs. 199
Dedicated Hosting
Dedicated Server
Fully managed Servers in India
Starts at Rs. 4499
Linux Hosting
Linux Hosting
Reliable Linux web hosting plans
Starts at Rs. 69


Why has this issue occurred?

Even though this issue is related to your source code level, HostingRaja is ready to help you in resolving the problem.This problem or issues may be due to any one of the following reasons with HostingRaja Virtual Private Server or cloud:

  1. MX Record is not pointing to HostingRaja, In this case, you need to update the MX records, the MX record can only be updated where your domain is hosted/pointing.
  2. When the port number is wrong on your php mailer source code or missed any source codes. For example, class.smtp.php that needs to be included.It may also due to authentication failures like HostingRaja servers not allow sending the mail without encryption so you need to enter SMTPSecure = ‘tls’ as well as setting the proper username and password properties.
  3. When your IP might be blocked due to continuous spam mail generation and email providers like zoho or Gmail will notify these messages and they will block your IP it may be done immediately or it may reflect after some days.


How can we prevent it?

Use the below Source Code of PHP Mailer Provided By HostingRaja VPS or Cloud Server along with your appropriate authentication details:

 

Sendmail.php

<?php

function sendnewmail($msgnew,$emailidnew,$subjectnew)

{

      require_once("class.phpmailer.php");

      require_once("class.smtp.php");

      $mail = new PHPMailer();

 

      $mail->IsSMTP();     // set mailer to use SMTP

      $mail->Host = "smtp.gmail.com"; // specify main and backup server

      $mail->SMTPAuth = true;     // turn on SMTP authentication

      $mail->Username ="This email address is being protected from spambots. You need JavaScript enabled to view it.";  // SMTP username

      $mail->Password ="demo123"; // SMTP password

 

      $mail->From = "This email address is being protected from spambots. You need JavaScript enabled to view it.";

      $mail->FromName = "Hostingraja";

      $mail->AddAddress($emailidnew," ");

      //$mail->AddAddress("This email address is being protected from spambots. You need JavaScript enabled to view it.");                  // name is optional

      //$mail->AddReplyTo("This email address is being protected from spambots. You need JavaScript enabled to view it.", "Information");

 

      $mail->WordWrap = 50;                                 // set word wrap to 50 characters

      //$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments

      //$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name

      $mail->IsHTML(true);                                  // set email format to HTML

      $mail->SMTPDebug  = 2;

      $mail->Subject = $subjectnew;

      $mail->Body    = $msgnew;

      //$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

 

      if(!$mail->Send())

      {

        echo "Message could not be sent. <p>";

         echo "Mailer Error: " . $mail->ErrorInfo;

         exit;

      }

 

}

$htmldetails ="Welcome to HostingRaja";

$email = "This email address is being protected from spambots. You need JavaScript enabled to view it.";

$subject = "Sample welcome message";

sendnewmail($htmldetails,$email,$subject);

 

?>

 

Other 2 files class.smtp.php and class.phpmailer.php can be downloaded  from GitHub URL: https://github.com/PHPMailer/PHPMailer/releases

Under class.smtp.php you need to enter port number as 25

EX: const DEFAULT_SMTP_PORT = 25;

      public $SMTP_PORT = 25;

 

Under class.phpmailer.php you need to enter port number as 25

Ex: public $Port = 25;

 

Once everything got fixed, your php mailer starts working next check whether mail is going to inbox or spam.

Also, make sure that your IP is not blacklisted, if it blacklisted then you need to send the request to whitelist the IP address.IP Blacklisting can be checked through MX toolbox entering your domain name or IP address, it will display the details from where your IP address has been blacklisted and the reason behind its blacklisting

 

Note: You can check the mail and domain error logs using the command:

         tail -f /var/log/maillog

         tail -f /var/sentora/logs/domains/domainname-error.log

Here replace the domainname with your domain name.

 

If mails are in spam then you need to verify that SPF and DKIM records are present or not for your domain name. Contact our server support team to configure those records once it is done you need to wait for 24 hours propagation time.