您的位置:首页 > 编程语言 > PHP开发

PHP中关于邮件E-mail的发送案例

2017-03-08 18:09 288 查看
大家都熟悉在网页端利用网页发送邮件的验证方式,但具体如何实现的想必你也不是很清楚。今天,我为大家带来一个PHP发送邮件的简单案例。

以下是一个关于邮件发送的源代码,大家可以看看。

<html>

<head>

<title>邮件发送(runoob.com)</title>

</head>

<body>

<?php

if (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.com
user@example.com, anotheruser@example.com
User <user@example.com>
User <user@example.com>, Another User <anotheruser@example.com>
subject

电子邮件的主题。

message

所要发送的消息。



如这样,便是一个简易的邮箱的验证,但这个邮箱的验证方式是不安全的,在使用时使用者可以给这个邮箱的验证加上一个过滤器就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php 邮件 源代码