Jump to content


Photo

First script


  • Please log in to reply
11 replies to this topic

#1 mason20034

mason20034
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 29 August 2006 - 11:58 AM

hi this is the first php i have written but i am having trouble getting it to work, server supports php, and it runs fine the email just isnt getting recived. any ideas.
<?php
if(isset($_POST['submit'])) {
$to = "mason-@hotmail.com";
$subject = "Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$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 "blarg!";
}
?>


#2 Iceman512

Iceman512
  • Members
  • PipPipPip
  • Advanced Member
  • 81 posts

Posted 29 August 2006 - 01:56 PM

Hey Mason20034,

Don't know if this helps, but take a look here: http://webworld.simp...est.net/node/35

Hope it works for you,
Regards,
Iceman

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 29 August 2006 - 02:01 PM

hi this is the first php i have written but i am having trouble getting it to work, server supports php, and it runs fine the email just isnt getting recived. any ideas.
<?php
if(isset($_POST['submit'])) {
$to = "mason-@hotmail.com";
$subject = "Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$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 "blarg!";
}
?>


there are a couple issues with your syntax within your mail() function. let's clean things up a bit, and let me know if it's still not coming through:
<?php
if(isset($_POST['submit'])) {
  $to = "mason-@hotmail.com";
  $subject = "Form";
  $name_field = $_POST['name'];
  $email_field = $_POST['email'];
  $message = $_POST['message'];
  $headers = "From: $name_field <$email_field>\r\nReply-To: $email_field";

  echo "Data has been submitted to $to!";

  if (!mail($to, $subject, $body)) echo "blarg!";
  else echo "Data has been submitted to $to!"; 
} 
?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 29 August 2006 - 02:03 PM

The body of the message should contain just the message, not the headers. Put the headers in a separate variable:
<?php
if(isset($_POST['submit'])) {
$to = "mason-@hotmail.com";
$subject = "Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = stripslashes($_POST['message']);
 
$headers = "From: $name_field\n E-Mail: $email_field\n";
 
echo "Data has been submitted to $to!";
mail($to, $subject, $message, $headers);
} else {
echo "blarg!";
}
?>

Also, getting email to be recieved at Hotmail can be a challenge. There have been a number of threads in the past few weeks relating to it. Search this group to find them.

Ken

#5 mason20034

mason20034
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 29 August 2006 - 04:05 PM

no nottings working tried several scripts on sevral web hosts. begining to think php is not for me.
not using hotmail just used that address as i dint not want to give out my email address. i am using  ntlworld and outlook

#6 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 29 August 2006 - 04:11 PM

How is it not working? Is it giving you an error?

If the webserver has successfuly sent the mail, and you're sending it to Hotmail/Yahoo/Gmail there might be issues with either the content of the email and being caught as spam. Or the email is being redirected and most anti-spam software sees Relaying as a security issue.

#7 mason20034

mason20034
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 29 August 2006 - 04:14 PM

its showing the data has been submited to message. and ive checked my junk email box but there is noting there i cant understand it at all

#8 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 29 August 2006 - 04:16 PM

Are you using hotmail?  Hotmail Live?  If so I know I had to add the domain the mail was coming from into the trusted recipients list.

#9 mason20034

mason20034
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 29 August 2006 - 04:20 PM

no im using outlook and a ntlworld email address.
im using it on a free web hosting account for testing puroposes
the address is http://mailmev1.awar...ce.com/mail.htm

#10 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 29 August 2006 - 04:35 PM

no im using outlook and a ntlworld email address.
im using it on a free web hosting account for testing puroposes
the address is http://mailmev1.awar...ce.com/mail.htm


one thing: the way you have your check written in your first post, it will ALWAYS appear that your mail was sent properly. check my first post above and try sending it that way. are you still getting the message that it was sent correctly?
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#11 mason20034

mason20034
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 29 August 2006 - 04:40 PM

yes twice

#12 mason20034

mason20034
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 29 August 2006 - 04:49 PM

ive got to go on holiday for a week now. thanks to everyone who has helped me. if anyone comes up with a solution please post and i will tell you if it has been sucessfull in a weeks time.
cheers all, james




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users