我有这个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;
?>
答案 0 :(得分: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;
?>