March 8, 201016 yr Hi guys and girls, it has been a while since i have posted on here. hoping i can get some help.. its probably something really basic, but here is the score... i have built a php contact form, on the form there is a drop down menu that selects the team which the email should be sent to. no errors are being printed and the form prints on the website after it has been submitted... however... no email is being sent to any of selected address's... my code is below. i would greatly appreciate some help on this.. <?php $first_name_contact = $_POST['first_name_contact']; $surname_contact = $_POST['surname_contact']; $email_contact = $_POST['email_contact']; $contact_message = $_POST['contact_message']; $contact_subject = $_POST['contact_subject']; $email_object = $_POST['email_object']; if ( isset($first_name_contact) && isset($surname_contact) && isset($email_contact) && isset($contact_message) && isset($contact_subject) && isset($email_object) ) { //check first name if (strlen($first_name_contact) < 3) echo 'You must enter a longer name. <a href="javascript:history.back(-1);">Click here to go back</a>.'; //check surname elseif (strlen($surname_contact) < 3) echo 'You must enter a longer surname. <a href="javascript:history.back(-1);"Click here to go back.</a>'; // check email elseif (!preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/",$email_contact)) echo 'Please enter a valid email address, in this format: joebloggs@mymail.com. <a href="javascript:history.back(-1);">Click here to go back</a>.'; //check subject elseif (strlen($contact_subject) < 2) echo 'You must enter a subject <a href="javascript:history.back(-1);"Click here to go back.</a>'; //check message elseif (strlen($contact_message) < 30) echo 'Your message must be longer than 30 characters. <a href="javascript:history.back(-1);">Click here to go back</a>.'; else { ini_set("sendmail_from", " www.nextgensolutions.co.uk"); $to = $email_object; $from = "Next Gen Solutions"; $subject = "Next Gen Solutions"; $email_message = " Name: ".$first_name_contact." ".$surname_contact." Email Address: ".$email_contact." Subject: ".$contact_subject." Message: ".$contact_message." "; $print_message = " <b>Name:</b> ".$first_name_contact." </br> <b>Email Address:</b> ".$email_contact." </br> <b>Subject:</b> ".$contact_subject." </br> <b>Message: </b>".$contact_message." </br> <b>Your message has been sent to ".$email_object."</b></br> "; mail($to, $subject, $email_message ); echo '<p>Thank you for submitting your query, please allow up to 48 hours for confirmation</p> <p>You have submitted the following details:'; echo "<p>$print_message</p>"; } } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div class="form_text"><label for="select_team">Select a Team</label></div> <div class="form_fields"><select name="email_object" id="email_object"> <option value="info@nextgensolutions.co.uk" name="general" id="general">General Enquiries</option> <option value="affiliates@nextgensolutions.co.uk" name="affiliates" id="affiliates">Affiliates</option> <option value="sales@nextgensolutions.co.uk" name="sales" id="sales">Sales</option> <option value="repairs@nextgensolutions.co.uk" name="repairs" id="repairs">Repairs</option> <option value="feedback@nextgensolutions.co.uk" name="feedback" id="feedback">Feedback</option> </select></div> <br /><br /> <br /> <div class="form_text"><label for="first_name">First Name</label></div> <div class="form_fields"><input type="text" name="first_name_contact" id="first_name_contact" /></div> <br /><br /> <br /> <div class="form_text"><label for="second_name">Second Name</label></div> <div class="form_fields"><input type="text" name="surname_contact" id="surname_contact" /></div> <br /><br /> <br /> <div class="form_text"><label for="email_address">Email Address</label></div> <div class="form_fields"><input type="text" name="email_contact" id="email_contact" /></div> <br /><br /> <br /> <div class="form_text"><label for="contact_subject">Subject</label></div> <div class="form_fields"><input type="text" name="contact_subject" id="contact_subject" /></div> <br /><br /> <br /> <div class="form_text"><label for="message">Message:</label></div> <textarea type="text" name="contact_message" id="contact_message" cols="40" rows="8"/> </textarea> <br /><br /> <div id="contact_button_location"> <input name="Submit" type="submit" id="contact_submit" value="Submit" /> <input name="Reset" type="reset" id="contact_reset" value="Reset" /> </div></form> <?php ///end else } ?>
March 8, 201016 yr Author $to = $email_object; should be $to = $email_contact; I think... why should it be $email_contact? that would send the form to the user
March 8, 201016 yr This won't stop it working but: Name: ".$first_name_contact." ".surname_contact." should be Name: ".$first_name_contact." ".$surname_contact."
March 8, 201016 yr Author This won't stop it working but: Name: ".$first_name_contact." ".surname_contact." should be Name: ".$first_name_contact." ".$surname_contact." Thank you
March 8, 201016 yr Try adding some headers: <?php $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> This is taken from PHP Manual
March 8, 201016 yr I have this form working locally and sending mail. I had to remove ini_set("sendmail_from", " www.nextgensolutions.co.uk"); I know some providers require this, but just to let you know it works with my host
March 8, 201016 yr Author I have this form working locally and sending mail. I had to remove ini_set("sendmail_from", " www.nextgensolutions.co.uk"); I know some providers require this, but just to let you know it works with my host yeah my host requires that, i to have had it working on other servers.. i am with streamline... but funnily enough the code works on another one of my sites. it is very fustrating
March 8, 201016 yr Whenever your message headers do not work, simply try using the fifth parameter: Whenever your message headers do not work, simply try using the fifth parameter: <?php mail($to, $subject, $message, $headers, "-femail.address@example.com"); ?>
March 8, 201016 yr why should it be $email_contact? that would send the form to the user LMAO so it would! As you can see, I am still learning, and not paying close enough attention
March 8, 201016 yr mail($to, $subject, $message, $headers, "-finfo@nextgensolutions.co.uk"); info@nextgensolutions.co.uk where info would be your username for the account with streamline
March 8, 201016 yr Author mail($to, $subject, $message, $headers, "-finfo@nextgensolutions.co.uk"); info@nextgensolutions.co.uk where info would be your username for the account with streamline You are a bloody legend. thank you very much. and everyone for your help on this issue.
Create an account or sign in to comment