我有一个网站表单,有人可以给我发消息。他们必须输入他们的姓名,电子邮件和信息。
表单的作用是我收到电子邮件,他们输入的发件人姓名和电子邮件显示在电子邮件中,但不会显示在他们输入的邮件中。
任何人都可以看到问题所在吗?
这是HTML表单
<form method="post" action="php/mail.php" name="cform" id="cform">
<input name="name" id="name" type="text" class="col-xs-12 col-sm-6 col-md-6 col-lg-6" placeholder="Your name..." >
<input name="email" id="email" type="email" class=" col-xs-12 col-sm-6 col-md-6 col-lg-6 noMarr" placeholder="Your email..." >
<textarea name="message" id="message" cols="" rows="" class="col-xs-12 col-sm-12 col-md-12 col-lg-12" placeholder="Your message..."></textarea>
<input type="submit" id="submit" name="send" class="submitBnt" value="Send message">
</form>
这是使用的php / mail.com(连接详细信息已更改为匿名详细信息)
<?
require("class.phpmailer.php");
//form validation vars
$formok = true;
$errors = array();
//sumbission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');
//form data
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP - mail or smtp.domain.com
$mail->Host = "myhost.myprovider.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "info@myaddress.com"; // SMTP username
$mail->Password = "mypassword"; // SMTP password
$mail->From = "info@myaddress.com"; // SMTP username
$mail->AddAddress("info@myaddress.com"); // Your Adress
$mail->Subject = "New contact request from ME !";
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Body = "<p>You have recieved a new message from the enquiries form on your website.</p>
<p><strong>Name: </strong> {$name} </p>
<p><strong>Email Address: </strong> {$email} </p>
<p><strong>Subject: </strong> {$subject} </p>
<p><strong>Message: </strong> {$message} </p>
<p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";
if(!$mail->Send())
{
echo "Mail Not Sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
答案 0 :(得分:1)
正如您所说,没有理由显示name
和email
,而message
没有。{/ p>
答案 1 :(得分:0)
我认为你需要enctype for textareas ...但我不完全确定。试试吧,它不会伤到你:
<form enctype="multipart/form-data" method="post" action="php/mail.php" name="cform" id="cform">
答案 2 :(得分:0)
可能想看看这个类似的问题
有人遇到了同样的问题,所有必须做的就是将id和名称更改为不同的
Issue using $_POST with a textarea
至于显示主题的问题,我看到你评论过,除非你在其他一些未发布的代码中,否则你永远不会将主题传递给$_POST
编辑1:
如果您是手动设置主题,那么为什么尝试从$_POST
获取该主题以及尝试执行<p><strong>Subject: </strong> {$subject} </p>
将无效,因为$subject
没有来自{{1}的值}