douhe5092 2017-12-19 07:57
浏览 42
已采纳

在PHP POST中恢复数据

I have a small problem with my php server. I am trying to email data that I recover with the $ POST method. If I do this, the code works and the mail is sent:

<?php
header('Access-Control-Allow-Origin: *');
header('Content-type: text/json');
$nom = "";
if( isset($_POST['votre_nom']))
{
    $nom = htmlspecialchars($_POST['votre_nom']);
}
require_once('class.phpmailer.php');
require_once('class.smtp.php');
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "myemail@gmail.com";
$mail->Password = "!Paswword";
$mail->SetFrom("no-reply@domain.com", "TEST", 0);
$mail->Subject = "Test";
$mail->Body = "hello" . nom . ;
$mail->AddAddress("email@gmail.com", "Person One");
$mail->AddCC('email@gmail.com', 'Person Two');

 if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
 } else {
    echo "Message has been sent";
 }
?>

but when I add data, it gives me a 500 error, as in the following code:

<?php
header('Access-Control-Allow-Origin: *');
header('Content-type: text/json');
require_once('class.phpmailer.php');
require_once('class.smtp.php');
$nom = "";
$email = "";
if(isset($_POST['votre_nom']) && isset($_POST['votre_email']))
{
    $nom = htmlspecialchars($_POST['votre_nom']);
    $email = htmlspecialchars($_POST['votre_email']);
}   

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "myemail@gmail.com";
$mail->Password = "!Password";
$mail->SetFrom("no-reply@domain.com", "TEST", 0);
$mail->Subject = "TEST";
$mail->Body = "Prénom/Nom : " . $nom . 
              "</br>Email : " . $email .;
$mail->AddAddress("email@gmail.com", "Person One");
$mail->AddCC('email@gmail.com', 'Person Two');

 if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
 } else {
    echo "Message has been sent";
 }

?>

I do not understand where the error may come from, because when I check my JSON everything is there..

If anyone could give me a track to find the solution please :)

Thank you

  • 写回答

1条回答 默认 最新

  • dongzhui9936 2017-12-19 08:15
    关注

    the error is at the level of the following line:

    "</br>Email : " . $email .;
    

    It must be done as follows:

    "</br>Email : " . $email . "";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据