1

I've got a pretty straightforward form for my portfolio website but it's not sending emails to my inbox address.

Here's the HTML

<form method="post" action="contact.php">
        <label>Name <i class="fa fa-male"> </i> </label> <br />
        <input type="text" name="name" /> <br />

        <label>Email <i class="fa fa-envelope"> </i> </label> <br />
        <input type="email" name="email" /> <br />

        <label>Message <i class="fa fa-comment"> </i> </label> <br />
        <textarea rows="5" cols="50" name="message"></textarea> <br />

        <input type="submit" value="Send" />
</form>

And the PHP

<?php
$myemail = 'danieldrave@live.com';

// GET THE CONTENT
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['message'];

// BUILD THE MESSAGE
$to = $myemail;
$subject = "Client enquiry: $name";
$body = "$msg";

$headers = "From: $email";

// SEND EMAIL
mail($to, $subject, $body, $headers);

// ACKNOWLEDGEMENT OF MESSAGE
header('Location: thankyou.php');
?> 

For reference, the website does successful redirect to thankyou.php

WebDevDanno
  • 1,122
  • 2
  • 22
  • 50

1 Answers1

0

Couple of things to look at:

  1. Is your current hosting package able to / allowed to send emails ?
  2. I have seen many cases where PHP mail function is not supported by Windows based hosting.
  3. Put proper "Mail Header". For example, look at this
  4. If above points are well matched, then check junk,spam folder.
  5. You can opt for ready to use Mailer script - for example look at this
HashTeck
  • 36
  • 8
  • I've got an Ubuntu Droplet with Digital Ocean. How would I go about checking whether it can send mail from PHP contact forms? – WebDevDanno Aug 24 '14 at 18:29
  • Write a file and put there and save. Then run that file from browser. Check for "mail", "sendmail" etc. If they are not empty, it should be fine. – HashTeck Aug 24 '14 at 18:31