简体   繁体   English

从标题邮件PHP

[英]From headers mail php

When I try to add headers in mail function it doesn't work. 当我尝试在邮件功能中添加标题时,它不起作用。 However, my code seems to be good. 但是,我的代码似乎不错。

Maybe we can't make a dynamic 'From' header ? 也许我们不能创建动态的“发件人”标头?

var message = "";
var nomClient = $("#nom").val();
var mailClient = $("#mail").val();

$.ajax({
          method: "POST",
          url: "traitement.php",
          data: { monMessage: message, mailDuClient: mailClient, nomDuClient: nomClient }
      })

      /* Si succès */
      .done(function() {
           // Bug : le champs mail restait visible, donc on le cache
           $("#mail").addClass("cacher");
           // Affiche le message de succès
           $(".succes").animate().css("display", "block");
           // On attends 3,5 secondes puis on rafraichi la page
           setTimeout(function(){location.reload();}, 3500);
       })

       /* Si échec */
       .fail(function(jqXHR, textStatus, errorThrown) {
           alert('Un problème est survenu');
       });

And this is my PHP code : 这是我的PHP代码:

$to = "x.y@gmail.com";
$objet = "Nouvelle demande de devis";
$headers = 'From: '. $_POST['nomDuClient'] . ' <' .$_POST['mailDuClient']. '>'. "\r\n";
 //'X-Mailer: PHP/' . phpversion(). "\r\n";

$mail = mail($to, $objet, $_POST['monMessage'], $headers);
echo($mail);

The mail is correctly sent, but without "From" 邮件已正确发送,但没有“发件人”

I don't see anything wrong with the code you provided. 您提供的代码没有任何问题。 What you can do is this: 您可以执行以下操作:

$to = "x.y@gmail.com";
$objet = "Nouvelle demande de devis";
$headers = 'From: '. $_POST['nomDuClient'] . ' <' .$_POST['mailDuClient']. '>'. "\r\n";
 //'X-Mailer: PHP/' . phpversion(). "\r\n";

$message = "headers:[$headers]\nmessage:\n".$_POST['monMessage']

$mail = mail($to, $objet, $message, $headers);
echo($mail);

This way you will receive a mail with the headers in the message itself. 这样,您将收到一封邮件,其中包含邮件本身的标题。 There you can see whether they are correct, or if something is missing. 在这里,您可以查看它们是否正确,或者是否缺少某些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM