Tell a friend form not working
<?php
if ($_POST['friends-email']) {
$name = "Sender's Name";
$email = "sender@domain.com";
$recipient = preg_replace("/[^a-z0-9 !?:;,.\/_\-=+@#$&\*\(\)]/im", "", $_POST['friends-email']);
$recipient = preg_replace("/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient);
$mail_body = "Default Description";
$subject = "Default Subject";
$header = "From: " . $name . " <" . $email . ">\r\n";
mail($recipient, $subject, $mail_body, $header);
echo 'Thank you for recommending <br /> us!';
} else {
开发者_JAVA技巧echo '<form action="" method="post" name="send2friend" id="send2friend">
Friends Email*:
<input name="friends-email" id="friends-email" type="text" />
<input type="submit" value="continue" />
</form>';
}
?>
Not sure why this isn't working, I get the "thank you message" but the email is not delivered when I test using my own emails.
Just stating the obvious, but where you have put $email = "sender@domain.com";
, you are actually changing that to a variable right?
Do you have all PHP errors turned on and displaying?
error_reporting(E_ALL);
ini_set('display_errors', '1');
Use PHP interactive mode (php -a
)to deploy an email
$to = 'dummymailing@mailinator.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n"; mail($to, $subject, $message, $headers);
Then go here to check that it's received. This is just to check that it's not a problem with your email client - i.e. it's not blocking the email.
If you're still having problems, it could be something to do with the system's sendmail function. This post on serverfault provides a lot of detailed advice on debugging the sendmail function.
Have you tried the mail function with hardcoded values, to check phpmail is set up right?
Then if that works, replace each value one at a time, and you will find your bug. I am guessing it is you regular expression replace however.
Try enclosing the mail delivery in an if statement
精彩评论