Unable to send mails; error 500

https://techandblogs.ml

acc: epiz_27647177

Error Message

Unable to send mails, says error 500

Other Information

<?php require_once 'mail/PHPMailer/PHPMailer/PHPMailerAutoload.php';
$servername = "sql212.epizy.com";
$username = "epiz_27647177";
$password = "HIDDEN BY MOD";
$dbname = "epiz_27647177_001";
$email = $_POST['email'];
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO Email(EmailId)VALUES('$email')";

if (mysqli_query($conn, $sql)) {
  echo "Mail Registered Successfully";
} else {
  echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);

$mail = new PHPMailer;
echo '1'
$mail->CharSet = 'utf-8';

$mail->SMTPDebug = 2;

$mail->isSMTP();

$mail->Host = gethostbyname('smtp.gmail.com');

$mail->SMTPAuth = true;

$mail->Username = 'newsletter.techandblogs@gmail.com';

$mail->Password = 'HIDDEN BY MOD';

$mail->SMTPSecure = 'tls';

$mail->Port = 587;

echo '2'
$mail->setFrom('newsletter.techandblogs@gmail.com');

$mail->addAddress($email);

$mail->isHTML(true);

$mail->Subject = 'You have successfully registered for weekly newsletters! techandblogs.ml';

$mail->AltBody = You have registerd your mail to recieve newsletters from techandblogs.ml;

if (!$mail->send()) {

  echo 'Message could not be sent.';

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

} else {

  echo 'Check Mail';

}
echo '3'
?>

on execution, it says error 500 why.

I am using PHPMailer

IF doesnt send PHPsendMail. If you were on WP I’d suggested to use the WP Mail SMTP

1 Like

I am not in wordpress

yeah I know. Thats why i said IF you were on WordPress …

1 Like

So, the faulty lines are these:

echo '1'

,

echo '2'

and this:

$mail->AltBody = You have registerd your mail to recieve newsletters from techandblogs.ml;

You need to correct them in order for your code to run fine. So, the first two lines I listed should have a semicolon at the end, while the third line I listed should have text enclosed in double or single quotes, like this:

$mail->AltBody = "You have registerd your mail to recieve newsletters from techandblogs.ml";
1 Like

First of all, don’t share your password on the forum. I’ve reset your account to a new, random password.

As for the 500 error, this is a good place to start:

2 Likes