phpmailer - ajax发送参数无效的电子邮件

时间:2017-04-26 18:39:55

标签: php ajax phpmailer

我正在尝试使用Phpmailer库发送电子邮件。它非常基本但无法处理。

这是我的javascript代码。

function sendemail() {
    var $adtext = $("#ad").val();
         var $gonderentext = $("#mail").val();
         var $mesajtext = $("#mesaj").val();
  $.ajax({

       url: '/mail.php',
      type: 'post',
       data:{action:'call_this', ad: $adtext, gonderen: $gonderentext, mesaj: $mesajtext},
       success:function(html) {
        alert("İletişim mailiniz gönderildi.");
       }


  });

}

这是我的Php文件(mail.php)

<?php
 include( "class.phpmailer.php" );
 include( "class.pop3.php" );
 include( "class.smtp.php" );
if($_POST['action'] == 'call_this') {
SendMailWithGmailSMTP("deneme@senlikorg.com","İletişim Mail",$_POST['mesaj'],$_POST['mail']);


};




function SendMailWithGmailSMTP($to,$subject,$text,$maill)
{
$mail=new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth=true;
$mail->Host="ssl://pro06.ni.net.tr:465";
$mail->Username="deneme@senlikorg.com";
$mail->Password="xxx";
$mail->From=$maill;
$mail->FromName=$text;
$mail->CharSet="iso-8859-9";
$mail->AddAddress($to);
$mail->Subject=$subject;
$mail->IsHTML(true);
$mail->Body=$text;
if($mail->Send()) return true;
else echo $mail->ErrorInfo;

}




?>
你能帮我弄清楚是什么错了吗?提前致谢。祝你有个美好的夜晚。

2 个答案:

答案 0 :(得分:1)

我相信,问题是您在$_POST['mail']发布数据中使用的$_POST['gonderen']而不是ajax使用了错误的参数

尝试更改您的php行:

SendMailWithGmailSMTP("deneme@senlikorg.com","İletişim Mail",$_POST['mesaj'],$_POST['gonderen']);

另外,如果您在此行$mail->ErrorInfo;收到任何错误,请告诉我们。

答案 1 :(得分:0)

这完全是我的坏事。与我的主机提供商联系,发现我使用了错误的端口。感谢大家。