Jump to content

Archived

This topic is now archived and is closed to further replies.

mason20034

First script

Recommended Posts

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!";
}
?>

Share this post


Link to post
Share on other sites
Hey Mason20034,

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

Hope it works for you,
Regards,
Iceman

Share this post


Link to post
Share on other sites
[quote author=mason20034 link=topic=106066.msg423888#msg423888 date=1156852726]
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!";
}
?>

[/quote]

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:
[code]
<?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!";
}
?>
[/code]

hope this helps

Share this post


Link to post
Share on other sites
The body of the message should contain just the message, not the headers. Put the headers in a separate variable:
[code]<?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!";
}
?>[/code]

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.awardspace.com/mail.htm

Share this post


Link to post
Share on other sites
[quote author=mason20034 link=topic=106066.msg424095#msg424095 date=1156868431]
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.awardspace.com/mail.htm
[/quote]

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.