【发布时间】:2013-12-22 05:53:57
【问题描述】:
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "mail@domain.com";
$email_subject = "Website Enquiry";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['comment'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['phone']; // not required
$comments = $_POST['comment']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n\n";
$email_message .= "Email: ".clean_string($email_from)."\n\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n\n";
$email_message .= "Comments: ".clean_string($comments)."\n\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
require("404.html");
?>
<!-- place your own success html below
Thank you for contacting us. We will be in touch with you very soon.-->
<?php
}
die();
?>
这是我发送邮件的 php 代码,如果我想向多个收件人发送邮件,并且电子邮件收件人存储在数据库中,应该对此代码进行哪些更改。基本上我想实现任何 e 上存在的通知我功能-商务网站。所以我想在这段代码中实现mysql数据库连接,发送多封邮件,发送邮件后,该条目应该从数据库中删除。
【问题讨论】:
-
这是一个什么样的问题:“应该对此代码进行哪些更改”?我们怎么知道你想改变什么?你甚至没有告诉我们为什么你想要改变。
-
我想发送多封电子邮件....
-
那就做吧,你有什么问题?对不起,你不能简单地在这里转储一些代码,而不是添加任何细节到你想做的事情以及为什么你不能做你想做的事情并期望其他人的帮助!试着从读者的角度思考:他不知道你的问题在这……
-
并且:这里有一个问题的一般规则:首先你必须自己尝试,只有当你失败时,然后你应该在这里问. 并且添加您迄今为止的尝试,并说明失败的原因。
标签: php email connection