首页 文章

简单的PHP邮件问题[关闭]

提问于
浏览
0

我有这个PHP邮件,到目前为止工作,但当我收到邮件我没有从联系表格中获得名称,电子邮件或电话信息,我只是得到主题和消息 . 我怎么能解决这个问题?非常感谢提前 .

<?php
$name       = @trim(stripslashes($_POST['name'])); 
$from       = @trim(stripslashes($_POST['email'])); 
$tel       = @trim(stripslashes($_POST['tel'])); 
$subject    = @trim(stripslashes($_POST['subject'])); 
$message    = @trim(stripslashes($_POST['message'])); 
$to         = 'example@example.com';//replace with your email


$headers = "MIME-Version: 1.0";
$headers .= "Content-type: text/plain; charset=iso-8859-1";
$headers .= "From: {$name} <{$from}>";
$headers .= "Reply-To: <{$from}>";
$headers .= "Subject: {$subject}";
$headers .= "X-Mailer: PHP/".phpversion();

mail($to, $subject, $message, $headers);

die;

?>

1 回答

  • 0

    您不会在电子邮件的邮件正文中包含除 $message 之外的任何内容 . 有关更多信息,请参见this reference on mail() .

    我已经提供了一个示例,说明如何在下面的消息中包含其他变量:

    <?php
    $name       = @trim(stripslashes($_POST['name'])); 
    $from       = @trim(stripslashes($_POST['email'])); 
    $tel       = @trim(stripslashes($_POST['tel'])); 
    $subject    = @trim(stripslashes($_POST['subject'])); 
    $message    = @trim(stripslashes($_POST['message'])); 
    $to         = 'yorchdiazc@hotmail.com';//replace with your email
    
    $headers = "MIME-Version: 1.0";
    $headers .= "Content-type: text/plain; charset=iso-8859-1";
    $headers .= "From: {$name} <{$from}>";
    $headers .= "Reply-To: <{$from}>";
    $headers .= "Subject: {$subject}";
    $headers .= "X-Mailer: PHP/".phpversion();
    
    // add name, email, tel to message - choose whichever markup you wish
    $message_body = "
    Name = " . $name . "<br>
    Email = " . $email . "<br>
    Tel = " . $tel . "<br>
    Message = " . $message;
    
    mail($to, $subject, $message_body, $headers);
    
    die;
    
    ?>
    

相关问题