First code not working.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wayneio
Forum Newbie
Posts: 6
Joined: Tue Jan 11, 2011 7:58 am

First code not working.

Post by wayneio »

Code: Select all

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  mail( "xxx", "Feedback Form Results",
    $message, "From: $email" );
  header( "Location: http://www.waynecovell.co.uk" );
?>
<form method="post" action="sendmail.php">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
This is my HTML & PHP. As far as i can tell, it should work. It redirects to the right page after it has been submittedd, yet i get no email. Its hosted on http://www.waynecovell.co.uk/form.html.

Any advice please?
Last edited by wayneio on Fri Nov 14, 2014 3:10 pm, edited 1 time in total.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: First code not working.

Post by social_experiment »

Try this

Code: Select all

<?php
 $mailMessage =  mail( "wayne.s.covell@gmail.com", "Feedback Form Results",
    $message, "From: $email" );
 if ($mailMessage) {
   // redirect
 } 
 else {
   echo 'Email not sent'; 
 }
?>
You are using $_POST in your form, use $_POST when accessing the variables.

Code: Select all

<?php
 $email = $_POST['email'] ;
 $message = $_POST['message'] ;
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
wayneio
Forum Newbie
Posts: 6
Joined: Tue Jan 11, 2011 7:58 am

Re: First code not working.

Post by wayneio »

Hi, thanks for your advice, however when i tried it, i still recieved no email.
My hosting does say it supports PHP, and I assume that it would not even redirect if PHP was not enabled, so it can't be that problem
bigjoe11a
Forum Newbie
Posts: 9
Joined: Mon Jan 17, 2011 2:57 pm
Location: Ohio, USA
Contact:

Re: First code not working.

Post by bigjoe11a »

Hi! I didn't thing you would mind. I have a sample for you below. and This does work, and it has been tested...

Code: Select all

<?php

$toname = $_POST['name'];
$to = $_POST['email'];

$subject = "Reply from web site";

$linkurl =  '<a href="Http://www.df-barracks.com">Delta Force Barracks</a>';

$my_message = <<<TEXT
<br> Hello $toname <br>
Welcome too my web site 
<br>
Thanks <br />
Admin <br />
RE:  Delta Force Barracks. <br />
<br />
<br> Follow this link to log in<br>
<br />
<a href='http://www.df-barracks.com">Delta Force Barracks</a>";

TEXT;

$from = "Your Name <Your email>";
$headers = "From : $from";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  
mail($to,$subject,$my_message,$headers);
echo "Email sent<br />";	

?>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: First code not working.

Post by social_experiment »

wayneio wrote:however when i tried it, i still recieved no email.
Here is a basic example (it's similar to what bigjoe11a posted) pasted

Code: Select all

<?php
 $to = 'someone@domain.com';
 $subject = 'hi';
 $message = 'just a test message';

 mail($to, $subject, $message) or echo 'Email wasnt sent';
?>
Also try with a different email address (if you haven't already)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
bigjoe11a
Forum Newbie
Posts: 9
Joined: Mon Jan 17, 2011 2:57 pm
Location: Ohio, USA
Contact:

Re: First code not working.

Post by bigjoe11a »

Did you ever get this to work. I never did here back from you,
Post Reply