简单的Php邮件丢失了一些位

时间:2011-11-24 13:30:15

标签: php mailer

我复制了一些PHP邮件程序,并在某些时候让它工作。但问题是,我认为它缺少了我想要的东西,我需要将最终的电子邮件输出显示如下:

姓名:[此处发件人姓名]
主题:[这里的主题]
消息:[此处留言]

看看上面的格式是否可以完成我想在某个时候添加公司输入字段。这是他下面的php邮件:

<?php 
//print_r($_POST);
    if(isset($_POST['_save'])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $subject = $_POST['subject'];

        if (empty($name) || empty($email) || empty($subject) || empty($message)) {
            if (empty($name))
                $error['name'] = "Please enter your Full Name";
            if (empty($email))
                $error['email'] = "Please enter a valid Email Address";
            if (empty($subject))
                $error['subject'] = "Please Write a Subject";
            if (empty($message))
                $error['message'] = "lease write a message, inquiries or other concerns above";
        }
        else { //if not empty

            $headers="From: {$email}\r\nReply-To: {$email}"; //create headers for email
            mail('email@domain.com',$subject,$message,$headers); //mail the message;
            $success = "Thank you! You're email has been sent.";
            #done;
        }
    }
?>

2 个答案:

答案 0 :(得分:3)

关于第一个问题,请更改

mail('email@domain.com',$subject,$message,$headers);

$content="Name: ".$name."<br>Subject: ".$subject."<br>Message: ".$message;
mail('email@domain.com',$subject,$content,$headers);

至于你的第二个问题,正如Jan所说,在表单中添加公司名称字段,并与名称/主题/消息变量完全相同。

答案 1 :(得分:2)

您可以随时添加公司输入,只需调整以下示例:

   $email_message = '
        Name: ' . $name . '<br />
        Subject: ' . $subject . '<br />
        Message: ' . $message . '
        ';


    $headers="From: {$email}\r\nReply-To: {$email}"; //create headers for email
    $semi_rand = md5(time());  
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";  

    $headers .= "\nMIME-Version: 1.0\n" .  
                "Content-Type: multipart/alternative; boundary=\"{$mime_boundary}\"";  

    $email_message .= "This is a multi-part message in MIME format.\n" .  
                    "Your email application may not support this format.\n\n" . 
                    "--{$mime_boundary}\n" .  
                    "Content-Type:text/html; charset=\"utf-8\"\n" .  
                    "Content-Transfer-Encoding: 8bit\n\n" . 
                    $email_message;

    $email = mail('email@domain.com',$subject,$email_message,$headers); //mail the message;
    if($email){
        $success = "Thank you! You're email has been sent.";
    }

我使用上面的示例调整了您的标题,因为并非每个电子邮件客户端都会接受您的电子邮件。告诉我这是否是你需要的。