jester275 Posted August 20, 2008 Share Posted August 20, 2008 Hey guys, Got a quick question for you. I am using the php mail function with an xhtml form to allow prospective customers to submit enquiries. The form is embedded on a page called contact.html and looks like this: <form method="POST" action="emailsubmit.php" onsubmit="return check(this);"> <table> <tr> <td>Name:</td><td><input type="text" name="name" size="30"></td> </tr> <tr> <td>Your Email address:</td><td><input type="text" name="email" size="30"></td> </tr> <tr> <td>Your Query/Comment:</td><td><textarea rows="8" name="message" cols="70"></textarea></td> </tr> <tr></tr> <td></td><td><input type="submit" value="Send Email!" name="submit"></td> </table> </form> This points to a php script on a page called emailsubmit.php. The code on this page looks like this: <?php //**If submit is set then send mail to [email protected] and print thanks for submitting email message**// if(isset($_POST['submit'])) { $to = '[email protected]'; $subject = 'TM Akers Enquiry'; $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; //**Body is made up of the name specified in the name text box, the senders manually enetered email address and their message**// $body = "From: $name\n E-Mail: $email\n Message:\n $message"; echo '<br />'; echo '<br />'; echo 'Thanks for submitting your email. Tim will get back to you as soon as possible.'; mail($to, $subject, $body); echo '<br />'; echo '<br />'; echo '<br />'; } else { echo "For some reason your email attempt failed! Please try again later."; } ?> Despite my best efforts, the form submits but does not send the email. The first echoed message appears when submitted, but is then followed by the second echoed message once a user clicks on contact.html again. I have no idea why! I have had this script running on a different server, and it has worked a treat! Any clues? Many Thanks, James Link to comment https://forums.phpfreaks.com/topic/120584-php-mail-function/ Share on other sites More sharing options...
jester275 Posted August 20, 2008 Author Share Posted August 20, 2008 Ah one other thing....the site is live at www.timakersantiques.com/contact.html......just in case you want to see what I mean. It's probably really simple, but I have been sitting at it and can't spot the problem! Cheers, James Link to comment https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621374 Share on other sites More sharing options...
revraz Posted August 20, 2008 Share Posted August 20, 2008 Many ISP's require the FROM: header to be added, so try mail($to, $subject, $body, "FROM:[email protected]"); Link to comment https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621376 Share on other sites More sharing options...
jester275 Posted August 20, 2008 Author Share Posted August 20, 2008 Hey! Thanks for getting back to me. I tried adding a from header earlier and just tried it again then. Sadly, no joy! Any other ideas? Do you think it could be something with the hosting I have just switched to? They have php 5 running on a linux server Cheers, James Link to comment https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621394 Share on other sites More sharing options...
revraz Posted August 20, 2008 Share Posted August 20, 2008 Could be the email address you are sending it to is blocking it as spam. Do you have access to your server log for your webhost? It will tell you there if mail send failed. Link to comment https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621434 Share on other sites More sharing options...
jester275 Posted August 20, 2008 Author Share Posted August 20, 2008 I just changed the email address it was it too originally, and the emails are going through to that account. However, it does not explain the strange goings on with the two echoed messages. One problem of two sorted though :-P Cheers Link to comment https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621449 Share on other sites More sharing options...
revraz Posted August 20, 2008 Share Posted August 20, 2008 I don't understand what you mean when you say "The first echoed message appears when submitted, but is then followed by the second echoed message once a user clicks on contact.html again." Which error do they get, "For some reason your email attempt failed! Please try again later."? If so, that should not appear unless they go right to emailsubmit.php without going to contact.html first. Link to comment https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621452 Share on other sites More sharing options...
jester275 Posted August 20, 2008 Author Share Posted August 20, 2008 Sorry for not being clear.... When the form is submitted a message is echoed informing a user that their message has been recieved. As you can see, this is done in the same if statement that send s the message. Below this if statement is an else statement that prints: "For some reason your email attempt failed! Please try again later. Alternatively send us an email to <a href='mailto:[email protected]'>[email protected]</a>" Currently, when a form is submitted on the site, the first statement is printed (Thanks for submitting your email. x will get back to you as soon as possible). However, if a user attempts to click on contact.html again, the else statement randomly prints. If you want to see it, the site is at www.timakersantiques.com/contact.html Cheers once again, James Link to comment https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621456 Share on other sites More sharing options...
jester275 Posted August 20, 2008 Author Share Posted August 20, 2008 Hey Revraz, I am a complete penis. I just found what was wrong and of course, it was so bloody obvious. That's the problem with staring at something for so long! Thanks for all your help, James Link to comment https://forums.phpfreaks.com/topic/120584-php-mail-function/#findComment-621472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.