Php 关于新MySQL数据库条目的电子邮件通知
我一直在使用网络教程创建博客,我有一个有效的评论系统,但我希望当用户添加评论时,我会收到一封电子邮件。如果你能解释一下我是如何执行通知的,我会非常高兴的。非常感谢您的帮助 现行表格:Php 关于新MySQL数据库条目的电子邮件通知,php,mysql,email,notifications,Php,Mysql,Email,Notifications,我一直在使用网络教程创建博客,我有一个有效的评论系统,但我希望当用户添加评论时,我会收到一封电子邮件。如果你能解释一下我是如何执行通知的,我会非常高兴的。非常感谢您的帮助 现行表格: <form id="commentform" method="post" action="process.php"> <p><input type="hidden" name="entry" id="entry" value="<?php echo $id; ?>" /&
<form id="commentform" method="post" action="process.php">
<p><input type="hidden" name="entry" id="entry" value="<?php echo $id; ?>" />
<input type="hidden" name="timestamp" id="timestamp" value="<?php echo $commenttimestamp; ?>">
<input type="text" name="name" id="name" title="Name (required)" /><br />
<input type="text" name="email" id="email" title="Mail (will not be published) (required)" /><br />
<input type="text" name="url" id="url" title="Website" value="http://" /><br />
<br />
<textarea title="Your Comment Goes Here" name="comment" id="comment"></textarea></p>
<p><input type="submit" name="submit_comment" id="submit_comment" value="Add Comment" /></p>
</form>
如果您正在寻找可以发送电子邮件的PHP代码,下面是一个供您查看的源代码。在将注释插入数据库之前或之后插入代码以发送电子邮件
<?php
//define the receiver of the email
$to = 'youraddress@example.com';
//define the subject of the email
$subject = 'Test email';
//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail.";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
:
对于邮件功能
如果可用,PHP必须具有访问
发送过程中系统上的sendmail二进制文件
编译时。如果您使用其他邮件
程序,如qmail或postfix
确保使用适当的sendmail
随附的包装纸。PHP将
首先在路径中查找sendmail,
然后在以下方面:
/usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib。
强烈建议您
sendmail可从您的路径访问。
此外,编译PHP的用户必须
具有访问sendmail的权限
二进制的
如果您正在寻找可以发送电子邮件的PHP代码,下面是一个供您查看的源代码。在将注释插入数据库之前或之后插入代码以发送电子邮件
<?php
//define the receiver of the email
$to = 'youraddress@example.com';
//define the subject of the email
$subject = 'Test email';
//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail.";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
:
对于邮件功能
如果可用,PHP必须具有访问
发送过程中系统上的sendmail二进制文件
编译时。如果您使用其他邮件
程序,如qmail或postfix
确保使用适当的sendmail
随附的包装纸。PHP将
首先在路径中查找sendmail,
然后在以下方面:
/usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib。
强烈建议您
sendmail可从您的路径访问。
此外,编译PHP的用户必须
具有访问sendmail的权限
二进制的
如果我想让电子邮件显示在评论表单中输入的信息,该怎么办?我需要它,以便它向我发送评论的名称、电子邮件和条目。$message
变量保存您的消息。使用字符串连接来创建所需的消息并发送该消息。我是否可以使用Mamp测试该消息。当我输入评论时,我似乎没有收到任何电子邮件。你需要在机器上运行邮件服务器。更多信息。同时阅读答案的更新。如果我想让电子邮件显示在评论表单中输入的信息,该怎么办?我需要它,以便它向我发送评论的名称、电子邮件和条目。$message
变量保存您的消息。使用字符串连接来创建所需的消息并发送该消息。我是否可以使用Mamp测试该消息。当我输入评论时,我似乎没有收到任何电子邮件。你需要在机器上运行邮件服务器。更多信息。同时阅读答案的更新。不要使用addslashes转义数据库查询的数据。使用mysql\u real\u escape\u string
,或者更好的是,使用准备好的查询……偶尔看到注入工作是很有趣的。不要使用addslashes为数据库查询转义数据。使用mysql\u real\u escape\u string
,或者更好的是,使用准备好的查询……偶尔看到注入工作是很有趣的。