I have a registration script that sends email through Gmail SMTP with the below script.
i received errors (SMTP Error: Could not connect to SMTP host. )
Please what is wrong with this code.
i received errors (SMTP Error: Could not connect to SMTP host. )
Please what is wrong with this code.
Code:
<?php
require_once('Connections/dbcon.php');
if (isset($_POST['formsubmitted'])) {
$error = array();//Declare An Array to store any error message
if (empty($_POST['name'])) {//if no name has been supplied
$error[] = 'Please Enter a name ';//add to array "error"
} else {
$name = $_POST['name'];//else assign it a variable
}
if (empty($_POST['lname'])) {//if no name has been supplied
$error[] = 'Please Enter a name ';//add to array "error"
} else {
$lname = $_POST['lname'];//else assign it a variable
}
if (empty($_POST['EmailAd'])) {
$error[] = 'Please Enter your Email ';
} else {
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['EmailAd'])) {
//regular expression for email validation
$EmailAd = $_POST['EmailAd'];
} else {
$error[] = 'Your EMail Address is invalid ';
}
}
if (empty($_POST['Password'])) {
$error[] = 'Please Enter Your Password ';
} else {
$Password = $_POST['Password'];
}
require_once("phpmailer/class.phpmailer.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'ssl://smtp.gmail.com:465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = 'mymail@gmail.com'; // Change this to your gmail adress
$mailer->Password = 'mypassword'; // Change this to your gmail password
$mailer->From = 'mymail@gmail.com'; // This HAVE TO be your gmail adress
$mailer->FromName = 'Registration Success!'; // This is the from name in the email, you can put anything you like here
$mailer->Body = 'Your username: '.$EmailAd.' | Your password is: "'.$Password.'';
$mailer->Subject = 'JobSearch Nigeria';
$mailer->AddAddress($_POST['EmailAd']);
if(!$mailer->Send())
{
echo "<script>alert('Registration failed.')</script>";
}
else
{
echo "<script>alert('Registration Success! Please logon to more fetures.')</script>";
mysql_query("INSERT INTO users(name, lname, EmailAd, Password)VALUES('$name', '$lname','$EmailAd', '$Password')");
}
}
Comment