PHPMailer not working in my server

i cant send mail from my server using phpmailer

here is the example code

  `          <?php
     * This example shows making an SMTP connection with authentication.

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that

require 'phpMailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "host";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 465;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
/ /Username to use for SMTP authentication
$mail->Username = "";
//Password to use for SMTP authentication
$mail->Password = "xxxxxxxxxx";
//Set who the message is to be sent from
$mail->setFrom('', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('', 'First Last');
//Set who the message is to be sent to 
$mail->addAddress('', 'John Doe');
 //Set the subject line 
 $mail->Subject = 'PHPMailer 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('phpMailer/examples/contents.html'), dirname(__FILE__));
 //Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file

//send the message, check for errors
if  (!$mail->send()) {
   echo "Mailer Error: " . $mail->ErrorInfo;
  } else {
    echo "Message sent!";

For one thing, the line

/ /Username to use for SMTP authentication

should give a syntax error as you have a space between the two slashes.

its type by mistake its no a problem

What error are you getting?

See the accepted answer at to see how to implement a way to see the exception message.

1 Like

its take too much loading and than nothing will show

You didn’t define the SMTPSecure preference. It should either be tls or ssl. Make sure the ports are correct too. Try using port 25 or 587.

That isn’t an error message, I repeat, put your code in the try/catch in the website I linked to with the catch outputting the exception message so we have an idea as to what is wrong.

port is current

got this error now after change port

SERVER β†’ CLIENT: ESMTP Exim 4.87 #1 Mon, 01 Aug
2016 18:02:08 +0530 220-We do not authorize the use of this system to
transport unsolicited, 220 and/or bulk e-mail.




SERVER β†’ CLIENT: 220 TLS go ahead

Warning: stream_socket_enable_crypto(): Peer certificate CN=*' did not match expected’ in /home/megs8c16/public_html/phpMailer/class.smtp.php on line 355

SMTP Error: Could not connect to SMTP host.


SERVER β†’ CLIENT: 221 closing connection

SMTP connect() failed.

Mailer Error: SMTP connect() failed.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.