Jump to content

First script


mason20034

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!";
}
?>
Link to comment
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
Link to comment
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
Link to comment
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.
Link to comment
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.