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.
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:
MX Record is pointing to some other hosting provider,which needs to be pointed to your ip address where your domain is hosted.
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.
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:
$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->Password ="demo123"; // SMTP password
$mail->FromName = "Hostingraja";
$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";
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
$htmldetails ="Welcome to HostingRaja";
$subject = "Sample welcome message";
Other 2 files you can download from github i.e class.smtp.php,class.phpmailer.php
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