当我提交联系表单时,它会运行脚本并重定向回标题,但不会发送任何电子邮件。我想我的代码中有一些错误,但无法弄清楚在哪里。
HTML代码为:
<form action="../php/mail.php" method="POST" enctype="multipart/form-data" name="Email Form" class="pure-form pure-form-stacked">
<fieldset>
<label for="name">Name</label>
<input id="name" name="name" type="text" placeholder="Your Name">
<label for="email">Email</label>
<input id="email" name="email" type="email" placeholder="Your Email">
<label for="message">Message</label>
<!--<input id="password" type="password" placeholder="Your Password">-->
<input id="message" name="message" type="text" placeholder="Your Message">
<button type="submit" class="pure-button">Submit</button>
</fieldset>
</form>
PHP脚本是:
<?php
$from = $_POST["email"]; // sender
$name = $_POST["name"];
$message = $_POST["message"];
$message = wordwrap($message, 70);
mail("myemail@gmail.com","My Contact Form",$message,"From: $from\n");
header( 'Location: http://www.mywebsite.com');
?>
答案 0 :(得分:-1)
尝试下面的代码。
$to = "myemail@gmail.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" ;
mail($to,$subject,$txt,$headers);
header( 'Location: http://www.mywebsite.com');