php表单通过电子邮件发送电子邮件

时间:2015-09-22 06:57:10

标签: php email html-form-post

我是php新手并试图通过表单向我的Gmail发送电子邮件。点击提交,我没有在页面上看到任何错误,但我没有收到电子邮件。我从id和mail id存在,并且来自电子邮件ID在服务器上(确保不发送垃圾邮件)。

<?php
    if(isset($_POST['submit'])){
        $to = "existingmygamilid@gmail.com";
        $subject = "Pickup Request";
        $mailContent = $_POST['name'].$_POST['adress'].$_POST['mobile'].$_POST['email'].$_POST['message'];
        $message = "
        <html>
        <head>
        <title> Pickup Request</title>
        </head>
        <body>
        <p>Hey!... You got a pickup request.</p>
        ";

        // Always set content-type when sending HTML email
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

        // More headers
        $headers .= 'From: <existingemail@testdomain.com>' . "\r\n";

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

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" class="alt" method="POST">
    <div class="row uniform 50%">
        <div class="6u 12u$(xsmall)">
            <input name="name" placeholder="Name" type="text" />
        </div>
        <div class="6u$ 12u$(xsmall)">
            <input name="address" placeholder="Address" type="text" />
        </div>
        <div class="6u 12u$(xsmall)">
            <input name="mobile" placeholder="Mobile or Landline" type="text" />
        </div>
        <div class="6u$ 12u$(xsmall)">
            <input name="email" placeholder="Email" type="email" />
        </div>                            
        <div class="12u$">
            <textarea name="message" rows="6"></textarea>
        </div>
    </div>
    <ul class="actions">
        <li><input type="submit" value="Send message" /></li>
    </ul>
</form>

4 个答案:

答案 0 :(得分:1)

试试这个:

<ul class="actions">
    <li><input type="submit" value="Send message" name="submit" /></li>
</ul>

给出姓名&#39;用于提交按钮。其他明智的isset($_POST['submit']赢了工作

答案 1 :(得分:1)

试试这个

final Process p = new ProcessBuilder()
    .command("repo", "forall", "-c", "pwd; git status")
    // etc etc
    .start();

错误

  1. <?php if(isset($_POST['submit'])){ $to = "existingmygamilid@gmail.com"; $subject = "Pickup Request"; $mailContent = $_POST['name'].$_POST['adress'].$_POST['mobile'].$_POST['email'].$_POST['message']; $message = " <html> <head> <title> Pickup Request</title> </head> <body> <p>Hey!... You got a pickup request.</p><br><p>"; $message .= $mailContent; $message .= "</p></body></html>"; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers $headers .= 'From: <existingemail@testdomain.com>' . "\r\n"; mail($to,$subject,$message,$headers); } ?> <form action="" class="alt" method="post"> <div class="row uniform 50%"> <div class="6u 12u$(xsmall)"> <input name="name" placeholder="Name" type="text" /> </div> <div class="6u$ 12u$(xsmall)"> <input name="address" placeholder="Address" type="text" /> </div> <div class="6u 12u$(xsmall)"> <input name="mobile" placeholder="Mobile or Landline" type="text" /> </div> <div class="6u$ 12u$(xsmall)"> <input name="email" placeholder="Email" type="email" /> </div> <div class="12u$"> <textarea name="message" rows="6"></textarea> </div> </div> <ul class="actions"> <li><input type="submit" name="submit" value="Send message" /></li> </ul> </form>
  2. 中缺少属性(name="submit"
  3. 不使用submit
  4. 邮件正文中没有结束标记(缺少$mailContent</body>
  5. 错误声明<html>

答案 2 :(得分:1)

此条件在您的代码中失败

if(isset($_POST['submit']))

您需要为提交按钮指定name属性,它才有效 <input type="submit" name="submit" value="Send message" />

答案 3 :(得分:1)

更改此行

<input type="submit"  name="submit" value="Send message"/>