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
  date_default_timezone_set('Etc/UTC');

require 'phpMailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//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 = "xxxxxx@megsta.com";
//Password to use for SMTP authentication
$mail->Password = "xxxxxxxxxx";
//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 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
 $mail->addAttachment('phpMailer/examples/images/phpmailer_mini.png');

//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: 220-wc-122.atnoc.com 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.

CLIENT β†’ SERVER: EHLO www.megsta.com

SERVER β†’ CLIENT: 250-wc-122.atnoc.com Hello www.megsta.com
[64.131.71.248]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN
LOGIN250-STARTTLS250 HELP

CLIENT β†’ SERVER: STARTTLS

SERVER β†’ CLIENT: 220 TLS go ahead

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

SMTP Error: Could not connect to SMTP host.

CLIENT β†’ SERVER: QUIT

SERVER β†’ CLIENT: 221 wc-122.atnoc.com closing connection

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

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