简单的 PHP 邮件程序缺少一些位
我复制了一些 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 protected]',$subject,$message,$headers); //mail the message;
$success = "Thank you! You're email has been sent.";
#done;
}
}
?>
I copied some PHP mailer and at some point had it working. But the thing is, I think it's missing something I want specifically, I need to make the final email output display like below:
Name: [name of sender here]
Subject: [subject here]
Message: [message here]
See if the format above can be done I would like to add a company input field too at some point. here's he php mailer below:
<?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 protected]',$subject,$message,$headers); //mail the message;
$success = "Thank you! You're email has been sent.";
#done;
}
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于您的第一个问题,更改
为
至于您的第二个问题,正如 Jan 所说,将公司名称字段添加到您的表单中,并执行与名称/主题/消息变量完全相同的操作。
For your first question, change
to
As for your second question, as Jan states, add a company name field to your form and do exactly the same as with the name/subject/message variables.
您可以随时添加公司输入,只需调整以下示例:
我在上面的示例中稍微调整了标题,因为并非每个电子邮件客户端都会接受您的电子邮件。告诉我这是否是您所需要的。
You can add the company input any time you want by just adjusting the following example:
I adjusted your headers a bit with the example above because not every email client will accept your email. Tell me if this is what you need.