【问题标题】:properly setting email subject line delivered from email form正确设置从电子邮件表单传递的电子邮件主题行
【发布时间】:2012-09-21 15:12:56
【问题描述】:

我的网站有一个电子邮件表单,但问题是:当我收到一封电子邮件时,收件箱中的主题行会显示用户在表单中作为主题输入的任何内容。 id 喜欢覆盖它,以便每当收到电子邮件时。电子邮件标题中的主题始终是“来自您网站的查询”。在邮件正文中,我确定我不介意他们输入的具体主题,但是当我收到一封电子邮件时,我的收件箱中的 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."; 
}
?> 

【问题讨论】:

    标签: forms email header subject


    【解决方案1】:

    您似乎在别处设置了一个名为 $subject 的变量。

    $subject = $_POST['subject']; 
    

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

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

    尝试创建另一个变量以供第二次使用或更改它以满足您的需要。

    【讨论】:

    • 感谢您提供的信息。你能告诉我如何进行调整吗?我的技能仅限于 html/css 的东西。我迷失了这种特殊类型的代码。
    • 所以就在$to = $youremail; $mailsubject = 'Message received from'.$fromsubject.' Contact Page'; $body = $fromsubject.' 的下方添加$subject = "Your Message here"; 这将重置该变量以达到预期目的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-07
    • 1970-01-01
    • 2023-03-23
    • 2019-08-04
    • 2011-09-16
    • 1970-01-01
    相关资源
    最近更新 更多