HTML表单/PHP和MySQL邮件通知


HTML Form/PHP and MySQL email notification

完全初学者在PHP和想要一个小方向的网站,我正在创建。我希望该网站的管理员收到一封电子邮件与所有的形式信息,以及它被存储在数据库中。数据库存储的信息很好,只需要一个电子邮件通知。这是如何实现的?我的PHP代码是:

<?php
session_start();
include('connection.php');
$product = $_POST['product'];
$productcomments = $_POST['productcomments'];
$name = $_POST['name'];
$address = $_POST['address'];
$age = $_POST['age'];
$delivery = $_POST['delivery'];
mysql_query("INSERT INTO orderform(product, productcomments, name, address, age, delivery)VALUES('$product', '$productcomments', '$name','$address', '$age', '$delivery')");
header("location: google.com");
$to      = 'j_bussey@live.co.uk';
$subject = 'Order';
$message = 'Product: ' . $product . '<br /> Product Comments: ' . $productcomments . '<br /> ';
$headers = 'From: webmaster@example.com' . "'r'n" .
    'Reply-To: webmaster@example.com' . "'r'n" .
    'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
mysql_close($con);
?>

这是一个非常基本的邮件函数示例。在这里阅读更多关于mail()手册。

$email = $_POST['email'];
$subject = "Email Subject";
$message = "Email Message Body";
mail($email, $subject, $message, "from: admin@yourdomain.com");

PHP有一个很棒的mail()函数。我从这里的文档页面中获取:http://us2.php.net/manual/en/function.mail.php

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "'r'n" .
    'Reply-To: webmaster@example.com' . "'r'n" .
    'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

既然你已经抓取了变量,你只需在上面的代码中编辑$message变量,看起来像这样:

$message = 'Product: ' . $product . '<br /> Product Comments: ' . $productcomments . '<br /> ';

等等。如果你不想假设他们启用了html电子邮件,你可以使用'n而不是<br />

编辑:您还需要将header('Location: google.com');更改为header('Location: http://www.google.com');或在电子邮件发送后想要重定向的任何地方。