0

I am creating a simple Django/Bootstrap website hosted on a VM running apache.

The path to my website is var/www/experiment/

I have followed this excellent tutorial on creating a php mailer contact form. I was having an issue with php not being installed on the account, but running sudo apt-get install libapache2-mod-php5 has solved this.

I also tried a second script given to me by a friend who has used it on several websites.

My problem is that the contact form emails are not being sent. I have checked it with 2 different email accounts and I have checked the spam folders in case. As I said, I have also checked two separate scripts.

What else could be wrong or needs to be changed/configured at my end?

My mailer.php file is located in var/www/experiment/php is this the right location?

Would anyone have a link to a better tutorial on using php mailer and apache?

EDIT: added code

Bootstrap - HTML

<form name="contactform" method="post" action="http://location_of_my_web_app/php/mailer.php"class="form-horizontal" role="form">

<div class="form-group">
<label for="inputName" class="col-lg-2 control-label">Name</label>
    <div class="col-lg-10">
    <input type="text" class="form-control" id="inputName" name="inputName" placeholder="Your Name">
    </div>
</div>
<div class="form-group">
<label for="inputEmail1" class="col-lg-2 control-label">Email</label>
    <div class="col-lg-10">
    <input type="text" class="form-control" id="inputEmail" name="inputEmail" placeholder="Your Email">
    </div>
</div>
<div class="form-group">
<label for="inputSubject" class="col-lg-2 control-label">Subject</label>
    <div class="col-lg-10">
    <input type="text" class="form-control" id="inputSubject" name="inputSubject" placeholder="Subject Message">
    </div>
</div>
<div class="form-group">
<label for="inputPassword1" class="col-lg-2 control-label">Message</label>
    <div class="col-lg-10">
    <textarea class="form-control" rows="4" id="inputMessage" name="inputMessage" placeholder="Your message..."></textarea>
    </div>
</div>

<div class="form-group">
<center>
    <div class="col-lg-offset-2 col-lg-10">
    <button type="submit" class="btn btn-primary">Send Message</button>
    </div>
</center>
</div> 
</form>

PHP

<?php
/* Set e-mail recipient */
$myemail = "my_address@gmail.com";

/* Check all form inputs using check_input function */
$name = check_input($_POST['inputName'], "Your Name");
$email = check_input($_POST['inputEmail'], "Your E-mail Address");
$subject = check_input($_POST['inputSubject'], "Message Subject");
$message = check_input($_POST['inputMessage'], "Your Message");

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */

$subject = "Someone has sent you a message";

$message = "

Someone has sent you a message using your contac form:

Name: $name
Email: $email
Subject: $subject

Message:
$message

";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: http://location_of_my_thank_you_page/Static/contact_thankyou.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>

</body>
</html>
<?php
exit();
}
?>
Community
  • 1
  • 1
Deepend
  • 4,057
  • 17
  • 60
  • 101

1 Answers1

0

Are you using PHP's mail() function, or connecting to a server and sending mail via SMTP? Whatever the case, the official PHPMailer website has a variety of examples. Do note that if you want to test sending mail via SMTP, you can always configure a gmail account and mess around with it.

https://github.com/PHPMailer/PHPMailer/tree/master/examples

Synchro
  • 35,538
  • 15
  • 81
  • 104
9997
  • 1,187
  • 1
  • 9
  • 14
  • I am using the php mail() function. I updated the question to show my code – Deepend Mar 17 '14 at 20:10
  • 1
    http://stackoverflow.com/questions/5335273/how-to-send-mail-using-php Use this as a guide for fixing up your code. :) The mail() function expects 4 parameters. – 9997 Mar 17 '14 at 20:16
  • I did not know that. I added in $name so my mail function is now mail($myemail, $name, $subject, $message); - Is this correct? I'm still getting no message to my inbox – Deepend Mar 17 '14 at 20:44