目前,我有一个简单的PHP脚本,可以接受用户的电子邮件地址并将其写入MySQL数据库。下面的代码工作正常。

我该如何添加一项功能,通过电子邮件向新订户发送一些信息到他们提供的地址?

<?php
require_once 'login.php'; // database information

$db_server = mysql_connect($db_hostname, $db_username, $db_password)
    or die("Unable to connect to MySQL: " . mysql_error());

mysql_select_db($db_database)
  or die("Unable to select database: " . mysql_error());

$email = $_POST['email'];

$sql="INSERT INTO users (email)
VALUES ('$email')";

$result = mysql_query($sql);

if($result){
header('Location: ../thankyou.php');
}
else {
echo "ERROR";
}

mysql_close();
?>


谢谢!

最佳答案

回答您的问题,应该是这样的

email($new_subscribers_email_address,"topic goes here","message goes here");


顺便说一句,您不应该使用mysql_,并且mysql_将很快从php中删除。请改用PDO或MySQLi。

还请注意,您这里有一个SQL Injection漏洞

$sql="INSERT INTO users (email) VALUES ('$email')";


解决方案:mysql_real_escape_string,像

$sql="INSERT INTO users (email) VALUES ('".mysql_real_escape_string($email)."')";

10-07 19:19
查看更多