djadejones
18 Jun 2011, 01:44 PM
Hi guys,
I have been using the same contact form for all my sites but only recently noticed during tests (and from comments from one of my "clients") that half of the time, emails dont go through.
I have just put this code in to my new site to test and the contact form processed fine, got me to my success page which then counted down and redirected me to the home page.
I did this twice and all seemed fine but I still havent had my test emails in my inbox.
This is the code I use:
HTML
<form action="processform.php" method="post">
<label for="name">Name</label><input type="text" id="name" name="name" />
<label for="email">Email address</label><input type="text" id="email" name="email" />
<label for="topic">Subject</label><input type="text" id="topic" name="topic" />
<textarea id="comments" name="comments" rows="5" cols="30"></textarea>
<button type="submit" id="sendmessage">Send</button>
</form>
PHP
<?php
// Pick up the form data and assign it to variables
$name = $_POST['name'];
$email = $_POST['email'];
$topic = $_POST['topic'];
$comments = $_POST['comments'];
// Build the email (replace the address in the $to section with your own)
$to = 'my e-mail address';
$subject = "New message: $topic";
$message = "$name said: $comments";
$headers = "From: $email";
// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);
// Redirect
header("Location: success.html");
I have tried sending to 2 different email addresses, also checked junk mail folders, nothing in there.
Have also tried amending this bit:
// Build the email (replace the address in the $to section with your own)
$to = 'my e-mail address';
$subject = "New message: $topic";
$message = "$name said: $comments";
$headers = "From: $email";
to:
// Build the email (replace the address in the $to section with your own)
$to = 'my e-mail address';
$subject = "New message: $topic";
$message = "$name said: $comments";
$headers = "From: adey@email.com";
$headers = "Reply-To: $email";
so that the email is coming from the email address on my server with the reply-to address having the senders email and still not receiving anything at all!
Any help appreciated.
Adey
I have been using the same contact form for all my sites but only recently noticed during tests (and from comments from one of my "clients") that half of the time, emails dont go through.
I have just put this code in to my new site to test and the contact form processed fine, got me to my success page which then counted down and redirected me to the home page.
I did this twice and all seemed fine but I still havent had my test emails in my inbox.
This is the code I use:
HTML
<form action="processform.php" method="post">
<label for="name">Name</label><input type="text" id="name" name="name" />
<label for="email">Email address</label><input type="text" id="email" name="email" />
<label for="topic">Subject</label><input type="text" id="topic" name="topic" />
<textarea id="comments" name="comments" rows="5" cols="30"></textarea>
<button type="submit" id="sendmessage">Send</button>
</form>
PHP
<?php
// Pick up the form data and assign it to variables
$name = $_POST['name'];
$email = $_POST['email'];
$topic = $_POST['topic'];
$comments = $_POST['comments'];
// Build the email (replace the address in the $to section with your own)
$to = 'my e-mail address';
$subject = "New message: $topic";
$message = "$name said: $comments";
$headers = "From: $email";
// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);
// Redirect
header("Location: success.html");
I have tried sending to 2 different email addresses, also checked junk mail folders, nothing in there.
Have also tried amending this bit:
// Build the email (replace the address in the $to section with your own)
$to = 'my e-mail address';
$subject = "New message: $topic";
$message = "$name said: $comments";
$headers = "From: $email";
to:
// Build the email (replace the address in the $to section with your own)
$to = 'my e-mail address';
$subject = "New message: $topic";
$message = "$name said: $comments";
$headers = "From: adey@email.com";
$headers = "Reply-To: $email";
so that the email is coming from the email address on my server with the reply-to address having the senders email and still not receiving anything at all!
Any help appreciated.
Adey