如何解决填写表单时接收访客信息的电子邮件
我必须解决这个问题。.所以我在我的网站(html / css / js)上有一个表格,一旦客户填写了它,而不是数据库中的注册,我想收到一封电子邮件。我是php的初学者,希望您能帮我..以下是我的PHP代码。
<?php
// Define some constants
define( "RECIPIENT_NAME","my name " );
define( "RECIPIENT_EMAIL","******@***.com" );
// Read the form values
$success = false;
$userName = isset( $_POST['username'] ) ? preg_replace( "/[^\s\S\.\-\_\@a-zA-Z0-9]/","",$_POST['username'] ) : "";
$lastName = isset( $_POST['lastname'] ) ? preg_replace( "/[^\s\S\.\-\_\@a-zA-Z0-9]/",$_POST['lastname'] ) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/",$_POST['email'] ) : "";
$userPhone = isset( $_POST['phone'] ) ? preg_replace( "/[^\s\S\.\-\_\@a-zA-Z0-9]/",$_POST['phone'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Phone:|Content-Type:)/",$_POST['message'] ) : "";
// If all values exist,send the email
if ( $userName && $lastName && $senderEmail && $userPhone && $message) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $userName . "";
$msgBody = " Last Name: ". $lastName . " Email: ". $senderEmail . " Phone: ". $userPhone . " Message: " . $message . "";
$success = mail( $recipient,$headers,$msgBody );
//Set Location After Successsfull Submission
header('Location: contact.html?message=Successfull');
}
else{
//Set Location After Unsuccesssfull Submission
header('Location: contact.html?message=Failed');
}
?>
解决方法
我建议您使用库PHPMailer来发送电子邮件。 需要配置电子邮件,PHPMailer会自动执行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。