Contact form not sending email
I'm coding my first ever PHP contact form. I've been working on it all day. Looking up everything on Google and I can't get a answer. The contact from goes to the success page and still nothing goes into my inbox...........
PHP:
<?php
// Define some constants
define( "RECIPIENT_NAME", "name" );
define( "RECIPIENT_EMAIL", "name@gmail.com" );
define( "EMAIL_SUBJECT", "Message" );
// Read the form values
$success = false;
$sender = isset( $_POST['sender'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['sender'] ) : "";
$email = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From: |To: |BCC: |CC: |Subject: |Content-Type:)/", "", $_POST['message'] ) : "";
//If all values exist, send the email
if ( $sender && $email && $message ) {
$recipient = RECIPIENT_NAME . " <" . RECIPENT_EMAIL . $email . ">";
$headers = "From: " . $sender . " <" . $email . ">";
$success = mail( $recipient, EMAIL_SUBJECT, $message, $headers );
}
// Return an appropriate reponse to the browser
if( isset($_GET["ajax"]) ) {
echo $success ? "success" : "error";
} else {
?>
<html>
<head>
<title>Thanks!</title>
</head>
<body>
<?php if ( $success ) echo "<h2>Thanks for sending your message! We'll get back to you shortly.</h2>" ?>
<?php if ( !$success ) echo "<h2> Sorry, There was a problem sending your message. Please try again.</h2>" ?>
<p> Click your browser's back button to return to the page</p>
</body>
</html>
<?php
}
?>
Is there anything wrong with it?
Heres the HTML
<form id="contactForm" action="process.php" method="post">
<label for="sender">Your Name</label>
<input type="text" name="sender" id="sender" placeholder="Your Name" required="required" maxlength="40">
<label for="email">Your Email Address</label>
<input type="email" name="email" id="email" placeholder开发者_Python百科="Please type your email address"
required="required" maxlength="50">
<label for="message">Your Message</label>
<textarea name="message" id="message" placeholder="Please type your message" required="required"
cols="50" rows="5" maxlength="10000"></textarea>
<div id="form-buttons">
<input type="submit" id="send-message" name="send-message" value="Send Email" />
<input type="button" id="cancel" name="cancel" value="Cancel" />
</div><!-- #form-buttons -->
Could someone take a look at this? I'm sure I did everything right.....
change this line:
$recipient = RECIPIENT_NAME . " <" . RECIPENT_EMAIL . $email . ">";
to:
$recipient = RECIPIENT_NAME . " <" . RECIPENT_EMAIL . ">";
that might be the issue
At least your line
$success mail( $recipient, EMAIL_SUBJECT, $message, $headers );
seems wrong, there should be an equality sign before mail
.
精彩评论