正确设置从电子邮件表单发送的电子邮件主题

时间:2012-09-21 15:12:57

标签: forms email header subject

我的网站有一个电子邮件表格,但问题是:当我收到一封电子邮件时,收件箱中的主题栏会显示用户在表格中输入的内容。 id喜欢覆盖它,以便每当有电子邮件进来时。电子邮件标题中的主题始终是“来自您网站的查询”。在邮件正文中,我确定不介意他们输入的具体主题,但是当我收到一封电子邮件时,我的收件箱就像是一致性。

这是当前的代码:

<?php session_start();
if(isset($_POST['Submit'])) {   if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'xxxxxxxxx';
$fromsubject = 'An inquiry from your website';
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$address = $_POST['address']; 
$city = $_POST['city']; 
$zip = $_POST['zip']; 
$country = $_POST['country']; 
$phone = $_POST['phone']; 
$subject = $_POST['subject']; 
$message = $_POST['message']; 
$headers = "From: $nome <$mail>\r\n";

    $to = $youremail; 
    $mailsubject = 'Message received from'.$fromsubject.' Contact Page';
    $body = $fromsubject.'

    The person that contacted you is  '.$fname.' '.$lname.'
     Address: '.$address.'
    '.$city.', '.$zip.', '.$country.'
     Phone Number: '.$phone.'
     E-mail: '.$mail.'
     Subject: '.$subject.'

     Message: 
     '.$message.'

    |---------END MESSAGE----------|'; 
echo "Thank you for inquiring. We will contact you shortly.<br/>You may return to our <a href='/index.html'>Home Page</a>"; 
                                mail($to, $subject, $body, $headers);
        unset($_SESSION['chapcha_code']);
   } else {
        echo 'Sorry, you have provided an invalid security code';
   }
 } else { 
echo "You must write a message. </br> Please visit our <a href='/contact.html'>Contact Page</a> and try again."; 
}
?> 

1 个答案:

答案 0 :(得分:1)

好像你在其他地方设置了一个名为$subject的变量。

$subject = $_POST['subject']; 

然后使用相同的变量发送邮件。

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

尝试为第二次使用创建另一个变量,或者在满足您的需求之前更改它。