hi all, I have been given this script however its not working!! Can anyone see whats going on? <? if (isset($_POST['submitted'])) { if(!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comments'])) { $body = "Name: {$_POST['name']}\n\nComments: {$_POST['comments']}"; mail('myemail@myemail.co.uk', 'Contact Form Submission', $body, "From: {$_POST['email']}"); echo '<p><em>Thank you for contacting us.</em></p>'; $_POST =array(); } else { echo '<p style="font-weight: bold; color: #C00">Please fill out the form compleatly.</p>'; } } ?> <p>Please fill out this form to contact us.</p> <form action="email.php" method="post"> <p>Name: <input type="text" name="name" size="30" maxlength="60" value="<? if (isset($_POST['name'])) echo $_POST['name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="30" maxlength="80" value="<? if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Comments: <textarea name="comments" rows="5" cols="30"><? if (isset($_POST['comments'])) echo $_POST['comments']; ?></textarea></p> <p><input type="submit" name="submit" value="Send!" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> PHP:
Could you post what error you're getting? It would save 90% of the troubleshooting time If no error is displayed on your browser please check your error log
Check to see if your server allows for PHP mail. I had this problem once and it drove me crazy trying to figure it out.
Yes, the script seems like it's fine. You should output everything to account for all the variables. If that doesn't work it's your mail server.
troubleshooting email is kind of hard, the problem could as well be on the recipient side. try adding something like this to understand if the email is being sent: $mail_sent = @mail('myemail@myemail.co.uk', 'Contact Form Submission', $body, "From: {$_POST['email']}"); if($mail_sent) { header('Location:contactus.php?msg=yes'); } else { header('Location:contactus.php?msg=no'); } PHP: adapted from http://php.net/manual/en/function.mail.php
That won't work. This checks if php calls that function, it can't check if server sent that mail try to add error_reporting(E_ALL); just after <?php and try to reply here with errors
php mail() returns trueif the mail was successfully accepted for delivery, false otherwise, hence it actually checks if the email was sent from php, then if there's no mail server that can deliver it it's another problem. If it this tells you the email was sent you can stop searching for the problem in your PHP code and configuration.
right guys all i can do is apologize, i have been a complete idiot and to be honest i can believe i have done it. In the action of the form it was trying to go to email.php, THIS DOES NOT EXIST! I am doing it all on new_index.php. i have now change this action to new_index.php and it all works so sorry to waste your time everyone
that's not true. Try to run localhost and try to mail it with that metod you psoted. It returns true in most cases, but I didn't received mail (never)