code:
<?php
include 'library.php';
include "classes/class.phpmailer.php";
if(isset($_POST['submit']))
{
$email = $_POST['email'];
$sql = "select email from login where email='".$email."'";
$results = mysqli_query($con,$sql);
$fetch = mysqli_num_rows($results);
if($fetch > 0)
{
echo "<p id='red'>Email already exist. Please register with different email id.</p>";
}
else
{
$query = "insert into student_login(email)values('$email')";
$result = mysqli_query($con,$query);
if($result==true)
{
$information="hello everyone";
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = 'example.com';
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = 'cpanel-username';
$mail->Password = 'cpanel-password';
$mail->AddReplyTo($email);
$mail->SetFrom("[email protected]", $email);
$mail->Subject = "Account Activation Link @Example";
$mail->AddAddress($email);
$mail->MsgHTML($information);
$send = $mail->Send();
if($send)
{
echo "<p id='green'>To activate your account. Please login your email and click on link.</p>";
}
else
{
echo "<p id='red'>Your message not sent.</p>";
}
}
else
{
echo "<p id='red'>Error!</p>";
}
}
}
?>
In this code I am using smtp mail function to sent an email quickly. But here what happen when I click on submit button. It show me successfull message but can’t receive an email. I do’t know where am I doing wrong. How can I fix this issue ?Please help me.
Thank You
2
Answers
I think that two things will help you in diagnosing such problems:
this is example how you can use mailer:
and use it:
omkara
A good idea is take test by parts, so:
First of all, ensure that there are no problems with sending emails, and then check your code!
1 – Can You send a e-mail using the web server (whitout use php)?
2 – Check if mail() function is enabled on your server, here’s how to do it.
3 – After try run your code check the php logs in the server.