我一生都无法获得我的 PHP 表单来发送电子邮件。我已经尝试了一百万种不同的方法来完成这项工作,到目前为止已经遵循了 10 个教程,但仍然没有运气。
这是我的表单和 php 代码(这些都在 index.php 文件中):
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
if ( isset($_POST['name']) && isset($_POST['email']) && isset($_POST['subject']) && isset($_POST['message']) ) {
$sender_name = $_POST['name'];
$email_address = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if ( !empty($sender_name) && !empty($email_address) && !empty($subject) && !empty($$message) ) {
$to = 'myemail@myemail.com';
$mailSubject = 'Contact Form Subject:' .$subject;
$mailSubject .= ' Sent from:' .$sender_name;
$body = $message;
$headers = 'From: ' .$email_address;
mail($to, $mailSubject, $body, $headers);
}
}
?>
<form method="post" action="index.php">
<div class="5grid">
<div class="row">
<div class="6u">
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="6u">
<input type="text" name="email" id="email" placeholder="Email" />
</div>
</div>
<div class="row">
<div class="12u">
<input type="text" name="subject" id="subject" placeholder="Subject" />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="message" id="message" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" value="Send" class="button form-button-submit"/>
<a href="#" class="button button-alt form-button-reset">Clear Form</a>
</div>
</div>
</div>
</form>
我根本没有收到任何错误,它只是不发送电子邮件。我在这里特别做错了什么吗?提前致谢。