好的,我已经联系了一份表格。我需要一个PHP脚本给我发电子邮件的信息。以下是我到目前为止的情况:
<?php
$emailSubject = 'Contact Form';
$webMaster = 'email-here';
$firstName = $_POST ['first_name'];
$lastName = $_POST['last_name'];
$emailAddress = $_POST ['email'];
$uploadFile = $_POST ['datafile'];
$questions = $_POST ['comments'];
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
好的,我已经尝试过并尝试提交一个上传文件。我找不到任何东西。要么努力,要么不行。请帮帮我。
此外,它说:
['first_name'];
是我输入输入名称的地方吗?
另外,我有一个感谢页面。它被称为:thank_you.html我需要在表单发送后显示!
答案 0 :(得分:0)
$to_name = stripslashes($_POST['to_name']);
$from_name = stripslashes($_POST['from_name']);
$subject = stripslashes($_POST['subject']);
$body = stripslashes($_POST['body']);
$to_email = $_POST['to_email'];
$attachment = $_FILES['attachment']['tmp_name'];
$attachment_name = $_FILES['attachment']['name'];
if (is_uploaded_file($attachment)) { //Do we have a file uploaded?
$fp = fopen($attachment, \"rb\"); //Open it
$data = fread($fp, filesize($attachment)); //Read it
$data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
fclose($fp);
}
//Let's start our headers
$headers = \"From: $from_name<\" . $_POST['from_email'] . \">\n\";
$headers .= \"Reply-To: <\" . $_POST['from_email'] . \">\n\";
$headers .= \"MIME-Version: 1.0\n\";
$headers .= \"Content-Type: multipart/related; type=\\"multipart/alternative\\"; boundary=\\"----=MIME_BOUNDRY_main_message\\"\n\";
$headers .= \"X-Sender: $from_name<\" . $_POST['from_email'] . \">\n\";
$headers .= \"X-Mailer: PHP4\n\";
$headers .= \"X-Priority: 3\n\"; //1 = Urgent, 3 = Normal
$headers .= \"Return-Path: <\" . $_POST['from_email'] . \">\n\";
$headers .= \"This is a multi-part message in MIME format.\n\";
$headers .= \"------=MIME_BOUNDRY_main_message \n\";
$headers .= \"Content-Type: multipart/alternative; boundary=\\"----=MIME_BOUNDRY_message_parts\\"\n\";
$message = \"------=MIME_BOUNDRY_message_parts\n\";
$message .= \"Content-Type: text/plain; charset=\\"iso-8859-1\\"\n\";
$message .= \"Content-Transfer-Encoding: quoted-printable\n\";
$message .= \"\n\";
/* Add our message, in this case it's plain text. You could also add HTML by changing the Content-Type to text/html */
$message .= \"$body\n\";
$message .= \"\n\";
$message .= \"------=MIME_BOUNDRY_message_parts--\n\";
$message .= \"\n\";
$message .= \"------=MIME_BOUNDRY_main_message\n\";
$message .= \"Content-Type: application/octet-stream;\n\tname=\\"\" . $attachment_name . \"\\"\n\";
$message .= \"Content-Transfer-Encoding: base64\n\";
$message .= \"Content-Disposition: attachment;\n\tfilename=\\"\" . $attachment_name . \"\\"\n\n\";
$message .= $data; //The base64 encoded message
$message .= \"\n\";
$message .= \"------=MIME_BOUNDRY_main_message--\n\";
// send the message
mail(\"$to_name<$to_email>\", $subject, $message, $headers);
http://icrontic.com/discussion/7019/php-email-form-with-attachments
答案 1 :(得分:0)
$em = $_POST ['email'];
list($username,$domain)=split('@',$em);
if(!checkdnsrr($domain,'MX')) echo 'please enter a proper e-mail address.';
这样的东西也很有用,这只是检查mx记录..