I am using this code on my server for sending mail, but not respond properly
<?php
function smtpmailer($to, $subject, $body)
{
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.zoho.com';
$mail->Port = 587;
$mail->Username = "contactform@abc.com";
$mail->Password = "********";
$mail->SetFrom("contactform@abc.com", 'af');
$mail->Subject = $subject;
$mail->Body = $body;
$mail->isHTML(true);
$mail->AddAddress($to);
$mail->headers = "Content-type: text/html; charset=utf-8
";
$mail->headers = "Content-type: image";
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
echo $error;
$error_no = 0;
} else {
$error_no = 1;
}
return $error_no;
}
if(isset($_POST['Submit']))
{
$name = $_POST['name'];
$email=$_POST['email'];
$msg = $_POST['comment'];
$error = $nameErr = $emailErr = $msgErr = "";
if(empty($name) && empty($email) && empty($msg))
{
$error ="please fill all fields";
}
else
{
if($name == "")
{
$nameErr = "Please enter your name";
}
else
{
if(!preg_match("/^[a-zA-Z ]*$/",$_POST['name']))
{
$nameErr = "only letters and white spaces are allowed";
}
}
if($email == "")
{
$emailErr = "please enter your email";
}
else
{
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
$emailErr = "Invalid Email Id";
}
}
}
if(empty($error) && empty($nameErr) && empty($emailErr) && empty($msgErr))
{
$message = '';
$message .= '
<p>Hello,</p>
<h4>We have recicved new contact request. Follwoing are detials. </h4>
<table border=0>
<tr><td>Name -- </td><td>'.$name.'</td></tr>
<tr><td>Email ID -- </td><td>'.$email.'</td></tr>
<tr><td>Message -- </td><td>'.$msg.'</td></tr>
</table>
<p>Reagrds, <br/>Flxpert Team</p>';
$to = 'vcv@outlook.com';
$sub = 'New contact request has logged.';
$to1=$email;
$subject1="Contact Successfull.";
$msg1 = '';
$msg1 = '<p>Hello '.ucfirst($name).',</p>
<table border=0>
<tr>
<td>Your contact request has successfully submitted. We will contact you as soon as possiable.</td>
</tr>
</table>
<p>Reagrds, <br/>Flxpert Team</p>';
smtpmailer($to, $sub, $message);
if( smtpmailer($to1, $subject1, $msg1) ){
$success="Your contact request has successfully submitted. We will contact you as soon as possiable. ";
} else{
$error="Something went wrong... ";
}
}
}
?>
It seems you are using PHPMailer library to send out mails & along with that using mail() function at the same time while executing request to send mail. Let's discuss this more in detail so you will come to know why is it happening?
You haven't shown all of your code in correct format and even the form is missing to trace the issue. However there are some points i think could be a problem and those are as follows
Add this before IsSMTP();
$mail = new PHPMailer;
USE
$mail->SMTPSecure = 'tls';
INSTEAD OF (SSL is used for Receiving mail not for sending)
$mail->SMTPSecure = 'ssl';
Remove the mail() function used within your PHPmailer function and try sending mail if it works then try implementing mail() function once the PHPmailer function ends.
Quick Note: You can add multiple PHPmailer function at the same time.
If ended up in no luck, try adding entire code in proper format along with form so will help you to track the issue.