Jump to content

What is wrong with my MAIL code????


tstout2

Recommended Posts

Hey everyone, I am having problems with my mail.php file.  Perhaps someone can correct me?  My server is shared hosting on GoDaddy.com with Windows, IIS 7 and PHP 5.

 

 

Thanks for the help!

 

<?PHP
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];

$ToEmail = "test@kls.com";
$ToSubject = "Message from kls.com";

$EmailBody =   "Name: $name\n 
			Email: $email\n
			Phone: $phone\n
			Message: $message\n";

$Message = $EmailBody;


$headers .= "Content-type: text; charset=iso-8859-1\r\n";
$headers .= "From:".$name." / ".$email."\r\n";

mail($ToEmail,$ToSubject,$Message, $headers);

?>

 

 

 

Link to comment
Share on other sites

tstout2,

 

If you set $success = mail($ToEmail,$ToSubject,$Message, $headers);

 

and the value of $success is false, take a look at this thread... 

 

http://www.phpfreaks.com/forums/index.php/topic,214908.0.html

 

By following the instructions and links therein, I got my mail function to work.

 

Good Luck.

 

Scot

Link to comment
Share on other sites

tstout2,

 

If you set $success = mail($ToEmail,$ToSubject,$Message, $headers);

 

and the value of $success is false, take a look at this thread... 

 

http://www.phpfreaks.com/forums/index.php/topic,214908.0.html

 

By following the instructions and links therein, I got my mail function to work.

 

Good Luck.

 

Scot

 

So change mail($ToEmail,$ToSubject,$Message, $headers); to $success = mail($ToEmail,$ToSubject,$Message, $headers); ?

 

I know nothing of PHP.  As for your link, it all has to do with linux. As stated above, I am on Windows 2008, IIS 7, PHP5.  I don't have a local php5.ini file, but Godaddy told me that there is one set for the system.

 

 

 

Link to comment
Share on other sites

Ok... I am really confused now!  If mailtest.php and mailform.php WORK, why doesn't mail.php? Mail.php is supposed to be getting the values from a flash form.

 

 

mailtest.php -----

<?php
$to = "email@domain.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "email@domain.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

 

 

mailform.php -----

<html>
<body>
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ; 
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail( "email@domain.com", "Subject: $subject",
  $message, "From: $email" );
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='mailform.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>
</body>
</html>

 

 

mail.php -----

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$headers = "From: ".$name." / ".$email."\r\n";

$ToEmail = "kayla@kaylalynnstout.com";
$ToSubject = "Message from KaylaLynnStout.com";

$EmailBody =   "Name: $name\n 
			Email: $email\n
			Phone: $phone\n
			Message: $message\n";

$Message = $EmailBody;

mail($ToEmail,$ToSubject,$Message, $headers);

?>

 

 

 

Link to comment
Share on other sites

you don't have your mailform.php FORM tag pointing to mail.php its pointing back to iself. Also I would use $_POST or $_GET not $_REQUEST

 

Please re-read the the post right above yours. These are three separate php scripts that I testing.  mailtest.php and mailform.php are two separate mail scripts that I used to make sure my system is performing correctly.  Those two scripts work.  mail.php is the scripts that came with my flash template website.  It gets the values from the flash form to be used in mail.php. mail.php does not work.  I want to get it working.

 

 

 

Link to comment
Share on other sites

The first step in troubleshooting is to make sure the data input to your code is what you expect? Have you echoed out what is in the $_POST array so that you know that the flash form is even sending anything to your script? You cannot get anything out of a script if there is garbage coming in.

Link to comment
Share on other sites

The first step in troubleshooting is to make sure the data input to your code is what you expect? Have you echoed out what is in the $_POST array so that you know that the flash form is even sending anything to your script? You cannot get anything out of a script if there is garbage coming in.

 

Sounds like a great plan... how do I do this?  I am completely new to PHP and don't know how to do what your suggesting.

 

 

Link to comment
Share on other sites

Current code....

 

<?php
echo "<pre>";
echo "GET:";
print_r($_GET);
echo "POST:";
print_r($_POST);
echo "</pre>";
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$headers = "From: ".$name." / ".$email."\r\n";

$ToEmail = "kayla@[..]";
$ToSubject = "Message from [..].com";

$EmailBody =   "Name: $name\n 
			Email: $email\n
			Phone: $phone\n
			Message: $message\n";

$Message = $EmailBody;

mail($ToEmail,$ToSubject,$Message, $headers);

?>

 

Link to comment
Share on other sites

Godaddy's shared Windows hosting does not officially include php (it is apparently installed but almost no extensions work.)

 

Are the scripts that do work being tried on the same account/domain as the one that does not?

 

You would need to provide information about your flash form to get help with why nothing is working.

Link to comment
Share on other sites

Godaddy's shared Windows hosting does not officially include php (it is apparently installed but almost no extensions work.)

 

Are the scripts that do work being tried on the same account/domain as the one that does not?

 

You would need to provide information about your flash form to get help with why nothing is working.

 

Godaddy's new Windows 2008 hosting with IIS 7 does include support for PHP5 only. Both of the scripts above that are working on the same account/domain as the one that does not.  This means one of two things... the code is incorrect, or the flash file is not directing to that script.  I am working on getting the .swf file open to check it out.  I am not at my normal PC, so I am trying to get it installed.

 

 

tstout2

Link to comment
Share on other sites

Alright, I haven't been able to get into the flash file yet, but I did take Godaddy's default PHP form mailer script  (see code below) and renamed it to mail.php.  I then tried the flash form and it worked (see email output below), so the flash form is calling the correct script and it is the original mail.php code. 

 

Now, I don't want to use Godaddy's default script because it it does not create an email from the form and then sends it, it merely sends an email (to an email address that must be specified in the hosting server) with the variables and values outputted. I want my form to create a normal looking email that I could respond to (much like what mailtest.php and mailform.php produce.

 

Godaddy's PHP Code----

<?php
$request_method = $_SERVER["REQUEST_METHOD"];
if($request_method == "GET")
{
	$query_vars = $_GET;
} 
elseif ($request_method == "POST")
{
	$query_vars = $_POST;
}

reset($query_vars);
$t = date("U");
$file = $_SERVER['DOCUMENT_ROOT'] . "\ssfm\gdform_" . $t;
$fp = fopen($file,"w");

while (list ($key, $val) = each ($query_vars)) 
{
	fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\r\n"); 
	fputs($fp,"$val\r\n");
	fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\r\n");
	if ($key == "redirect") 
	{ 
		$landing_page = $val;
	}
}

fclose($fp);

if ($landing_page != "")
{
	header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page");
} 
else 
{
	header("Location: http://".$_SERVER["HTTP_HOST"]."/");
}
?>

 

 

Godaddy's Output Email----

from test@gmail.com

to test@kls.com

date Thu, Sep 18, 2008 at 1:40 PM

subject Form submission from kls.com

mailed-by bounce.secureserver.net

 

 

email: [...]

message: test email from flash

name: Terry Stout

phone: 555.555.5555

-----------------------------------------------------------------

This e-mail was generated from a form submission on your website:

 

Link to comment
Share on other sites

I hop I don't sound too stupid, but look at the basic real quick. I think you cant have your script like this...

$EmailBody =   "Name: $name\n 
			Email: $email\n
			Phone: $phone\n
			Message: $message\n";

its got to be like

$EmailBody =   "Name: ".$name."\n 
			Email: ".$email"\n
			Phone: ".$phone."\n
			Message: ".$message."\n";

Just like using echo/print..."".$."".$.""

If I'm wrong, thats great, it'll save me time in the future.

Link to comment
Share on other sites

I hop I don't sound too stupid, but look at the basic real quick. I think you cant have your script like this...

$EmailBody =   "Name: $name\n 
			Email: $email\n
			Phone: $phone\n
			Message: $message\n";

its got to be like

$EmailBody =   "Name: ".$name."\n 
			Email: ".$email"\n
			Phone: ".$phone."\n
			Message: ".$message."\n";

Just like using echo/print..."".$."".$.""

If I'm wrong, thats great, it'll save me time in the future.

 

Didn't make a difference for me.  If you look back at the code for the two scripts that work, they don't use the syntax your suggesting.

 

 

 

Link to comment
Share on other sites

FINALLY!!!!   I had to do hours of research and piece together lots of code, but I finally have something that works the way I want it to.  Thanks to everyone for the help.

 

 

tstout2

 

Final Working Code----

<?php

/* Subject and Email Variables */

$subject = 'Message from KLS.com';
$to = 'email@kls.com';

/* Gathering Data Variables */

$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$message = $_POST['message'];

/* Build Email Body */	

$body = <<<EOD

Name: $name
Email: $email
Phone Number: $phone
Message: $message
EOD;

/* Build Email Headers */

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-To: " .$email. "\r\n";

/* Send Email */

$success = mail($to, $subject, $body, $headers);

?>

 

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.