Email script reports success, but email does not appear in my inbox
I created a form t开发者_JAVA技巧hat is linked to a PHP page like this:
<form method="get" action="contact.php">
<p>Nome:</p> <input type="text" name="name" class="name" /><br>
<p>E-mail :</p> <input type="text" name="mail" class="mail" /><br>
<p>Website:</p> <input type="text" name="website" class="website" /><br>
Mensagem: <textarea name="message" class="message" rows="2" cols="20"></textarea>
<input type="submit" value="Enviar" class="submit" />
</form>
The PHP page:
<?php
$field_name = $_GET['name'];
$field_email = $_GET['mail'];
$field_website = $_GET['website'];
$field_message = $_GET['message'];
$mail_to = '__munged__@gmail.com';
$subject = 'Message from a site visitor ' . $field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = "From: $field_email\r\n";
$headers .= "Reply-To: $field_email\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
// Print a message
alert('Message failed. Please, send an email to __munged__@template-help.com');
window.location = 'index.html';
</script>
<?php
}?>
I can't seem to figure out the problem. Thanks in advance.
If you had access to the web host I would say try to find the apache2.log file on an Ubuntu server this is located in /var/log/
but I don't know where this would be for you. Anyways, if you find this you can look at the last records in the log to see if apache is throwing an error during the execution of this command that is otherwise hidden from the user. It sounds like there is probably a problem with the mail server. Do you have one setup? are you using sendmail or some variant?
I recently had some related problems with sending mail, this might help you (but as I said before it is for linux)
php5 mail() function sendmail error
Check the smtp server settings in [mail function]
section of php.ini
file. The mail server probably received the message successfully otherwise it would return an error. I would try to use different mail server.
Its a simple method to do.
Remove Unused Spaces from subject. Do Not use dynamic variable with subject like $field_name.
use php5 @mail function
精彩评论