Note that there are some explanatory texts on larger screens.

plurals
  1. POBasic email form (php)
    primarykey
    data
    text
    <p>I'm trying to send a basic email from a form using PHP. The form is validated using jquery.validate.js (which is working fine), but I can't get the email to send. I simply keep getting the php file that is declared in the action when I submit.</p> <p>The site is <a href="http://designbydarren.com/nwh/alfie/" rel="nofollow">here</a>, the form looks like this:</p> <pre><code> &lt;form method="post" action="send-email.php" id="contact-form" class="form-horizontal" role="form"&gt; &lt;fieldset&gt; &lt;div class="col-12 col-md-6 col-lg-6 contact--left"&gt; &lt;div class="form-group"&gt; &lt;label for="name" class="col-12 control-label brand brand-font"&gt;Name&lt;/label&gt; &lt;div class="col-12"&gt; &lt;input type="text" class="form-control brand-font--standard" name="name" id="name"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="email" class="col-12 control-label brand brand-font"&gt;Email&lt;/label&gt; &lt;div class="col-12"&gt; &lt;input type="email" class="form-control brand-font--standard" name="email" id="email"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label for="phone" class="col-12 control-label brand brand-font"&gt;Telephone&lt;/label&gt; &lt;div class="col-12"&gt; &lt;input type="tel" class="form-control brand-font--standard" name="phone" id="phone"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="col-12 col-md-offset-1 col-md-5 col-lg-offset-1 col-lg-5 contact--right"&gt; &lt;div class="form-group"&gt; &lt;label for="message" class="col-12 control-label brand brand-font"&gt;Message&lt;/label&gt; &lt;div class="col-12"&gt; &lt;textarea class="form-control brand-font--standard" rows="6" name="message" id="message"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;div class="col-12"&gt;&amp;nbsp;&lt;/div&gt; &lt;div class="col-12"&gt; &lt;button type="submit" class="btn btn-block btn--orange brand-font"&gt;Submit&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>...and the send-email.php file looks like this:</p> <pre><code>&lt;?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "contact@designbydarren.com"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.&lt;br /&gt;&lt;br /&gt;"; echo $error."&lt;br /&gt;&lt;br /&gt;"; echo "Please go back and fix these errors.&lt;br /&gt;&lt;br /&gt;"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['phone']) || !isset($_POST['message'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $email_from = $_POST['email']; // required $phone = $_POST['phone']; // required $message = $_POST['message']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email)) { $error_message .= 'The Email Address you entered does not appear to be valid.&lt;br /&gt;'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The name you entered does not appear to be valid.&lt;br /&gt;'; } if(strlen($message) &lt; 2) { $error_message .= 'The message you entered do not appear to be valid.&lt;br /&gt;'; } if(strlen($error_message) &gt; 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($phone)."\n"; $email_message .= "Message: ".clean_string($message)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?&gt; &lt;!-- include your own success html here --&gt; Thank you for contacting us. We will be in touch with you very soon. &lt;?php } ?&gt; </code></pre> <p>I've tried using a few other examples i've found on the web but not got anything to stick yet. Apologies for the noob esque question but i'm more of a front-ender so have little idea about this type of thing (however basic it may seem to you guys)</p> <p>Thanks for your time!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload