Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何创建电子邮件表单PHP(HTML5)_Php_Html_Forms_Responsive - Fatal编程技术网

如何创建电子邮件表单PHP(HTML5)

如何创建电子邮件表单PHP(HTML5),php,html,forms,responsive,Php,Html,Forms,Responsive,我对php有点陌生,我只是想问一下,如何让“发送消息”按钮将我创建的表单上的输入信息发送到我的电子邮件中 代码如下: <section id="three"> <h2>Email Me!</h2> <p>You will receive a reply within 24-48 hours.</p> <div class="row"> <div class="8u 12u

我对php有点陌生,我只是想问一下,如何让“发送消息”按钮将我创建的表单上的输入信息发送到我的电子邮件中

代码如下:

    <section id="three">
    <h2>Email Me!</h2>
    <p>You will receive a reply within 24-48 hours.</p>
    <div class="row">
        <div class="8u 12u$(small)">
            <form method="post" action="MAILTO:sample@email.com">
                <div class="row uniform 50%">
                    <div class="6u 12u$(xsmall)"><input type="text" name="name" id="name" placeholder="Name" /></div>
                    <div class="6u$ 12u$(xsmall)"><input type="email" name="email" id="email" placeholder="Email" /></div>
                    <div class="12u$"><textarea name="message" id="message" placeholder="Message" rows="4"></textarea></div>
                </div>
            </form>
            <ul class="actions">
                <li><input type="submit" value="Send Message" /></li>
            </ul>
        </div>
        <div class="4u$ 12u$(small)">
            <ul class="labeled-icons">
                <li>
                    <h3 class="icon fa-home"><span class="label">Address</span></h3>
                    1234 Somewhere Rd.<br />
                    Nashville, TN 00000<br />
                    United States
                </li>
                <li>
                    <h3 class="icon fa-mobile"><span class="label">Phone</span></h3>
                    000-000-0000
                </li>
                <li>
                    <h3 class="icon fa-envelope-o"><span class="label">Email</span></h3>
                    <a href="#">hello@untitled.tld</a>
                </li>
            </ul>
        </div>
    </div>
</section>

给我发电子邮件!
您将在24-48小时内收到回复

  • 地址 某处路1234号
    田纳西州纳什维尔00000
    美国
  • 电话 000-000-0000
  • 电子邮件

谢谢

我不太确定,但是来自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);
?>

资料来源:

如果邮件已成功接受传递,则返回TRUE,否则返回FALSE

我推荐使用的是邮件发送服务,比如or,它们很容易使用,并且有相当简单的API。免费计划有很多可以提供的,你可以通过他们的api发送简单的html,这很好。


<?php
if(isset($_POST['submit'])) // on submit click no need to action of the form
{
$name = $_POST['name'];
$email = $_POST['email'];


$to = "somebody@example.com";
$subject = "My subject";
$body = "name:" . $name . "Email:" . $email;
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$body,$headers);
}
?>

我建议使用PHPMailer从PHP发送电子邮件。以下是实现这一目标的步骤

  • 去Github
  • 下载ZIP文件
  • 在您的公共html目录中解压缩它
  • 包括“/path/to/PHPMailer/phpmailerautoad.php”位于PHP脚本的顶部
  • 像平常一样从HTML表单中获取值
  • 这里有一个例子

    index.html
    
    <form action="index.php" method="post">
        <input type="email" name="email">
        <input type="text" name="name">
        <input type="text" name="subject">
        <input type="text" name="message">
    </form>
    
    index.php
    
    include '/path/to/PHPMailer/PHPMailerAutoload.php';
    
    $email = $_POST['email'];
    $name = $_POST['name'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    
    $mail = new PHPMailer;
    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'localhost'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = 'username'; // SMTP username
    $mail->Password = 'password'; // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption, "ssl" also accepted
    $mail->Port = 587; // TCP port to connect to
    
    $mail->setFrom('your email', 'your name'); // from
    $mail->addAddress($email, $name); // to
    $mail->isHTML(true); // if html
    
    $mail->Subject = $subject;
    $mail->Body = $message; //HTML
    
    if($mail->send()){
        echo 'Mail sent!';
    }
    else {
        echo 'Mail failed!';
    }
    
    index.html
    index.php
    包括“/path/to/PHPMailer/phpmailerautoad.php”;
    $email=$_POST['email'];
    $name=$_POST['name'];
    $subject=$_POST['subject'];
    $message=$_POST['message'];
    $mail=新的PHPMailer;
    $mail->isSMTP();//将邮件程序设置为使用SMTP
    $mail->Host='localhost';//指定主SMTP服务器和备份SMTP服务器
    $mail->SMTPAuth=true;//启用SMTP身份验证
    $mail->Username='Username';//SMTP用户名
    $mail->Password='Password';//SMTP密码
    $mail->SMTPSecure='tls';//启用TLS加密,也接受“ssl”
    $mail->Port=587;//要连接到的TCP端口
    $mail->setFrom('your email','your name');//从…起
    $mail->addAddress($email,$name);//到
    $mail->isHTML(正确);//如果html
    $mail->Subject=$Subject;
    $mail->Body=$message//HTML
    如果($mail->send()){
    回音“已发送邮件!”;
    }
    否则{
    回显“邮件失败!”;
    }
    
    Hi您所说的“提交时无需执行表单操作”是什么意思?如果我问您应该将此php代码附加到html5索引的什么位置,或者我应该为此创建一个.php文件,您是否介意?谢谢是的,您需要创建index.php文件在页面顶部创建此代码