我的jquery文件中有一个函数帖子,它将数据插入数据库并发送一封邮件。没有phpmailer工作正常,显示警报,但当我把phpmailer代码警报不工作(但插入数据库并发送电子邮件),有人知道为什么会发生这种情况,并为不良的英语,thx寻求帮助。
更新:我已经收到警报更改json_encode以返回webservice并更改警报(响应);返回警报(响应);关于邮政编码,但需要在关闭post方法后发出警报,如果不这样做,则返回警报不要出现,有些想法为什么需要在方法发布后获得返回的第二个警报,thx。
我的邮政编码
$.post('insert',{val: message,name: $("#firstName").val(),desktop_id: $("#desktop_id").val(),permis: $("#permis").val(),phone: $("#phone").val(),mail: $("#mail").val()}, function (response) {
//feedback
alert(response);
});
我的网络服务
$app->post('/insert', function(){
require_once('db/dbconnect.php');
$name = $_POST['name'];
$phone= $_POST['phone'];
$phone=(int)$phone;
$mail =$_POST['mail'];
$desktop_id = $_POST['desktop_id'];
$desktop_id=(int)$desktop_id;
$permis=$_POST['permis'];
$date = date("Y-m-d");
$data=array("name"=>$name,"phone"=>$phone,"mail"=>$mail,"desktop_id"=>$desktop_id,"permis"=>$permis,"date"=>$date);
$client=$db->client();
$result = $client->insert($data);
if($result){
$response = 'Success';
}
else{
$response = 'Error';
}
//I remove the variables data
include_once("phpmailer/PHPMailerAutoload.php");
$To = $destinatarios;
$Subject = $assunto;
$Message = $value;
$Host = 'mail.'.substr(strstr($usuario, '@'), 1);
$Username = $usuario;
$Password = $senha;
$Port = "587";
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$body = $Message;
$mail-> IsSMTP(); // telling the class to use SMTP
$mail-> Host = $Host; // SMTP server
$mail-> SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail-> SMTPAuth = true; // enable SMTP authentication
$mail-> Port = $Port; // set the SMTP port for the service server
$mail->addAttachment('mpdf/temp/doc.pdf');
$mail-> Username = $Username; // account username
$mail-> Password = $Password; // account password
$mail-> SetFrom($usuario, $nomeDestinatario);
$mail-> Subject = $Subject;
$mail-> MsgHTML($body);
$mail-> AddAddress($To, "");
if(!$mail-> Send())
{
}
else
{
}
echo json_encode($response, JSON_UNESCAPED_UNICODE);
});
答案 0 :(得分:0)
当您设置$response = 'Error: '. print($mail->ErrorInfo);
或$response = 'Success'
,然后设置echo json_encode($response, JSON_UNESCAPED_UNICODE)
时,您似乎正在尝试将格式不正确的字符串转换为JSON。