2

我复制了一些 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;
        }
    }
?>
4

2 回答 2

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 所说,在您的表单中添加一个公司名称字段,并与 name/subject/message 变量完全相同。

于 2011-11-24T13:39:29.257 回答
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.";
    }

我用上面的例子稍微调整了你的标题,因为不是每个电子邮件客户端都会接受你的电子邮件。告诉我这是不是你需要的。

于 2011-11-24T14:04:18.213 回答