大家都熟悉在网页端利用网页发送邮件的验证方式,但具体如何实现的想必你也不是很清楚。今天,我为大家带来一个PHP发送邮件的简单案例。
以下是一个关于邮件发送的源代码,大家可以看看。
<html><head><title>邮件发送(runoob.com)</title></head><body><?phpif (isset($_REQUEST['email'])) { // 如果接收到邮箱参数则发送邮件 // 发送邮件 $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail("someone@mail.com", $subject,$message, "From:" . $email); echo "邮件发送成功";} else { // 如果没有邮箱参数则显示表单 echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text'><br> Subject: <input name='subject' type='text'><br> Message:<br> <textarea name='message' rows='15' cols='40'> </textarea><br> <input type='submit'> </form>";}?></body></html>
大家应该都知道php中mail函数吧?就是这样:
bool mail ( string $to , string $subject , string$message[, string$additional_headers[, string $additional_parameters]] )
在此函数中:
to电子邮件收件人,或收件人列表。
本字符串的格式必须符合 » RFC 2822。例如:
user@example.comuser@example.com, anotheruser@example.comUser <user@example.com>User <user@example.com>, Another User <anotheruser@example.com> subject电子邮件的主题。
message所要发送的消息。