【问题标题】:Recover data in PHP POST在 PHP POST 中恢复数据
【发布时间】:2023-04-08 07:27:01
【问题描述】:

我的 php 服务器有一个小问题。 我正在尝试通过电子邮件发送使用 $ POST 方法恢复的数据。 如果我这样做,代码将起作用并发送邮件:

<?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";
 }
?>

但是当我添加数据时,它给了我一个 500 错误,如下面的代码:

<?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";
 }

?>

我不明白错误可能来自哪里,因为当我检查我的 JSON 时,一切都在那里..

如果有人可以给我一个找到解决方案的路线,请:)

谢谢

【问题讨论】:

  • 您检查过您的网络服务器的日志吗?比如Apache错误日志?

标签: php json email post


【解决方案1】:

错误在以下行的级别:

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

必须按如下方式进行:

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

【讨论】:

  • 是的!好的 !谢谢你:)
猜你喜欢
  • 2020-07-28
  • 2018-06-03
  • 2017-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-12
  • 1970-01-01
相关资源
最近更新 更多