今晚有很多问题需要制作功能性联系表格。搞乱了好几个小时后,我终于发现我只能在我的网络主机上使用SMTP。
有人可以建议我如何填写表格吗?
这是我目前的SMTP PHP表单
$mail = new PHPMailer();
//Your SMTP servers details
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "localhost"; // specify main and backup server or localhost
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "enquiries@c(hidden)y.co.uk"; // SMTP username
$mail->Password = "******"; // SMTP password
//It should be same as that of the SMTP user
$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = "Display Name";
$mail->AddAddress("enquiries@c(hidden)y.co.uk", "chapnolo"); //Email address where you wish to receive/collect those emails.
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $_POST['subject'];
$message = "Name of the requestor :".$_POST['fullname']." \r\n <br>Email Adrress :".$_POST['email']." \r\n <br> Query :".$_POST['query'];
$mail->Body = $message;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
header("Location: $redirect_url");
}
?>
我需要我的表单,以便我能够检索需要的电子邮件正文。
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$web = $_POST['web'];
$formcontent="From: $name \n Contact: $number \n Website: $web \n Message: $message";
$recipient = "enquiries@c(hidden)y.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email ";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
非常感谢帮助
答案 0 :(得分:0)
Metexora - 所以你没有任何代码问题,你只是没有告诉它给你发送姓名联系电话,电子邮件和邮件正文 - 只需更改:
$message = "Name of the requestor :".$_POST['fullname']." \r\n <br>Email Adrress :".$_POST['email']." \r\n <br> Query :".$_POST['query'];
到
$message = "Name of the requestor :".$name." \r\n <br>Email Adrress :".$email." \r\n <br> Phone number :".$number."\r\n <br> Message: ".$message."\r\n <br> Website: ".$web;
(注意:请注意,你在这里重新声明$ message,这不是真正推荐的做法,因为他们提到不同的东西,用户留言和电子邮件消息,你应该只使用改变的内容变量,如果它仍然引用相同的东西)