Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Contact form code not working

Featured Replies

Hi,

 

Can someone please advise me on this. I've read the pinned article on the top of this forum but too inexperienced to understand it. Also, really don't want all those expletives as well!!

 

So, the stage I'm at is this:

 

HTML

<form method="post" action="sendmail.php">
 <fieldset>
   <legend>Please enter your contact details and your enquiry in the fields below:</legend>
   <br />
   <p>
     <label for="fullname">Name:</label>
     <input type="text" name="fullname" id="fullname" class="txt" />
   </p>
   <p>
     <label for="email">Email Address:</label>
     <input type="text" name="email" id="email" class="txt" />
   </p>
   <p>
     <label for="telephone">Telephone:</label>
     <input type="text" name="telephone" id="telephone" class="txt" />
   </p>
   <p>
<label for="enquiry">Enquiry:</label>
<textarea name="enquiry"></textarea>
</p>
  <br />
<p><label for="comments">How would you like us to contact you:</label><br />
Please telephone me: <input type="checkbox" name="contactbyphone" value="Yes">
Email me the details please: <input type="checkbox" name="contactbyemail" value="Yes"><br />
</p>
<p></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
     </fieldset>
 </form>

 

And the php (which I'd prefer in as an external document)

<?php
if(isset($_POST['submit'])) {
$to = "TOEMAIL";
$subject = "Contact Form Test";
$name_field = $_POST['fullname'];
$email_field = $_POST['email'];
$telephone = $_POST['telephone'];
$enquiry = $_POST['enquiry'];
$contactbyphone = $_POST['contactbyphone'];
$contactbyemail = $_POST['contactbyemail'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "You're reading this cos the form was built by a complete n*bhead";
}
?>

Any advise greatly received.

Jo.

Edited by wizely

You're not specifying where the mail is coming from?

  • Author

I see that now, but would that stop everything working completely.

 

Excuse my ignorance of php - it's a new years resolution to get it sorted.

 

Thanks,

Yes it would. Try adding this variable:

 

$mail_from = "FROMEMAIL";

 

and change the mail function to:

 

mail($to, $subject, $body, "-f".$mail_from);

 

 

If that still doesn't work, your php.ini file has not specified a default sendmail_from address and you need to specify it by adding this code above the mail function.

 

ini_set("sendmail_from", $mail_from);

Edited by wizely

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.