Phpmailer is not working in the site

What is the Issue?

Website is having a contact form when user fill out it 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 email is not receiving on other end. We receive this issue from our registered Clients who have hosted their website on our VPS and Cloud Server, ensure that your MX record is pointing to some other hosters, if not then you need to proceed further with the following steps mentioned by us.

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 problem with HostingRaja Virtual Private Server or cloud:


  1. MX Record is pointing to some other hosting provider,which needs to be pointed to your ip address where your domain is hosted.

  2. You have given wrong port number 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 will not allow to send the mail without encryption so you need to enter SMTPSecure = ‘tls’ as well as setting proper username and password properties.

  3. Your IP may 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 you can download from github i.e class.smtp.php,class.phpmailer.php

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


Also make sure that your IP is not blacklisted, if so than you need to send request to whitelist  the IP address.IP Blacklisting can 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 reason behind it.


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/abcd.com-error.log