我在服务器上使用此代码发送邮件,但没有正确响应
<?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 'r'n";
$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... ";
}
}
}
?>
您似乎正在使用PHPMailer库发送邮件&以及在执行发送邮件的请求时同时使用mail()函数。让我们更详细地讨论一下,这样你就会知道为什么会发生这种情况?
您没有以正确的格式显示所有代码,甚至缺少跟踪问题的表单。然而,有一些点我认为可能是一个问题,这些是如下
将其添加到IsSMTP()之前;
$mail = new PHPMailer;
使用
$mail->SMTPSecure = 'tls';
INSTEAD OF(SSL用于接收邮件而非发送)
$mail->SMTPSecure = 'ssl';
删除PHPmailer函数中使用的mail()函数,如果它有效,请尝试发送邮件,然后在PHPmailer功能结束后尝试实现mail()功能。
快速提示:您可以同时添加多个PHPmailer功能
如果最后运气不好,请尝试以正确的格式添加整个代码和表单,这样可以帮助您跟踪问题。