Log in

View Full Version : Can't get a simple email form to work...



Graphicsgod
06-01-2007, 07:13 PM
I'm having problem with my email PHP form :mad:! I've been trying for a week now and nothing I've tried will send mail to my email!! What is it that I'm doing wrong?

I'm using Godaddy.com on a windows server. It works with both PHP and ASP, but ASP is preferred for a windows server. But all I've been getting is error or confirmation messages, but no email in my in-box! Is it me, or is it Godaddy.com?!?

Heres a sample of my form:


<div id="container">
<form id="form_4" name="sendmail" class="mail"
onsubmit="return validate_form_4(this)"
action="sendemail.php" method="post" target="_self">

<fieldset>
<legend>&nbsp;Personal&nbsp;Information&nbsp;</LEGEND>

<ul id="formFields">
<li><label class="desc" for="field17">Name:</label>
<span><input id="Fname" name="first_name" maxlength="200" class="field text"
size="14" class="memorize" value="" onkeypress="return handleEnter(this, event)"
onFocus="clearText(this)" />
<label class="tam">First</label></span>
<span><input id="Lname" name="last_name" maxlength="200" class="field text"
size="14" class="memorize" value="" onkeypress="return handleEnter(this, event)"
onFocus="clearText(this)" />
<label class="tam">Last</label></span>
<div id="hintanchor_1">
<a href="#" class="hintanchor"
onMouseover="showhint('Please type your (<b>REAL</b>) name.', this, event, '200px')">
<img src="images/about.gif" border="0" width="20" height="20" alt="" /></a>
</div>
</li>
<li>
<label class="desc" for="field8">Email:</label>
<div>
<input id="Email" name="email" maxlength="200" class="field text medium"
type="text" maxlength="255" class="memorize" value=""
onkeypress="return handleEnter(this, event)" onFocus="clearText(this)" />
</div>
<div id="hintanchor_2">
<a href="#" class="hintanchor"
onMouseover="showhint('Please input your (<b>REAL</b>) email address.', this, event, '150px')">
<img src="images/about.gif" border="0" width="20" height="20" alt="" /></a>
</div>
</li>
<li>
<label class="desc" for="field123">Attention:</label>
<div>
<select "id="Attnfield" name="Attn">
<option value=" General " selected="selected">General Message</option>
<option value=" Support ">Support</option>
<option value=" Sales/Billing ">Sales/Billing</option>
<option value=" Technical ">Technical</option>
</select>
</div>
</li>
<li>
<label class="desc" for="field124">Comments:
&nbsp;&nbsp;&nbsp;
<i><font size="-2" color="#919090">(No More than <u>1,000</u> Characters
please.)</font></i></label>
<div>
<textarea id="Comments" name="text_box" rows="10" cols="50"
class="field textarea medium"
style="width: 370px; font-family: Arial; font-size: 13px; z-index: 14"
onKeyDown="textCounter(this,'progressbar1',1000)"
onKeyUp="textCounter(this,'progressbar1',1000)"
onFocus="textCounter(this,'progressbar1',1000)"></textarea>
<div id="progressbar1" class="progress"></div>
<script>textCounter(document.getElementById("maxcharfield"),"progressbar1",1000)</script>
</div>
</li>
</ul>
<div class="buttons">
<center>
<font size="1">
<input id="submit" name="submit" class="button" type="submit" value="Send Message" />
<img src="images/spacer.gif" width="20" height="2" alt="" />
<input id="reset" name="reset" class="button" type="reset" value="Reset Form">
</font>
</center>
</div>
</fieldset>
</form>
</div>



As you can see, it's just a simple HTML email form. Now the php code pages.

Ver. 1:


<?php

$to = 'mymail@gmail.com';
$name = $_POST['first_name'];
$name = $_POST['last_name'];
$email = $_POST['email'];
$subject = $_POST['attn'];
$message = $_POST['text_box'];

else {
$from = 'From: '.$name.' <'.$email.'>';
}

$subject = stripcslashes($subject);
$body = stripcslashes($message);

if(mail($to, $subject, $body, $from)){

echo "Mail ($subject), was successfully sent.";
}

else {
echo "The email ($subject) could not be sent.";
}
if(mail(mail(mymail@gmail.com, $name, $subject, $message)) { header("Location: thanks.htm"); //Sends to New Page
echo "<p>TEXT</p>"; // Prints out some text
}
else {
echo "<p>An Error Occured, Please Resend<p>"; }

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>I.D. Tagem...Thanks!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- meta http-equiv="refresh" content="0;url=thanks.htm" -->

</head>
<body bgcolor="#ffffff" text="#000000">

<div>
<center>
<b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b>
<br>Your message has been sent
<p><a href="<?php print $continue; ?>">Click here to continue</a></p>
</center>
</div>

</body>
</html>


Ver. 2:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>

<?php
if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
}
if(empty($first_name) || empty($email) || empty($text_box )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = $attn;

$text_box = stripcslashes($text_box);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $text_box \n
From: $first_name ($email)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $email\r\n";

mail("mymail@gmail.com", $subject, $message, $from);

?>

<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $first_name ?> ( <?php echo $email ?> )
<br />

Attention: <?php echo $attn ?>
<br />
Message:<br />
<?php $text_boxout = str_replace("\r", "<br/>", $text_box);
echo $text_boxout; ?>
<br />
<?php echo $ip ?>

<br /><br />
<a href="thanks.htm"> Next Page </a>
</p>

</body>
</html>


Can anyone see a problem with that code that would prevent it from sending?!? Minus the name thing (ie. can't find an example for both "first" and "last" names in a PHP form field), so if anyone knows how to correct that, please feel free to post the code!

If Godaddy.com doesn't allow PHP email forms for some odd reason, you think I would get better results with ASP? And if so, what would the code look like? I've been working with PHP forms for a month now, ASP is still new to me.


Thanks for your time and help, Rob.

mbrodin
06-01-2007, 07:52 PM
Hi, Rob!

Try this code, and see if it send yet or gets any error(s);


<?php

// Are we going to send user to another location? True/False
$send_to_newPage = false;

$to = 'mymail@gmail.com';
$name = $_POST['first_name'] . " " . $_POST['last_name'];
$email = $_POST['email'];
$subject = $_POST['attn'];
$message = $_POST['text_box'];

$from = "From: " . $name . " <" . $email . ">";

$subject = stripslashes($subject);
$body = stripslashes($message);


if( $send_to_newPage )
{

if( mail($to, $name, $subject, $body) )
{
header("Location: thanks.htm"); //Sends to New Page
}
else
{
echo "<p>An Error Occured, Please Resend<p>";
}

}
else
{

if( mail($to, $subject, $body, $from) )
{
echo "Mail (" . $subject . "), was successfully sent.";
}
else
{
echo "The email (" . $subject . ") could not be sent.";
}

}

$name = stripslashes($name);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>I.D. Tagem...Thanks!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- meta http-equiv="refresh" content="0;url=thanks.htm" -->

</head>
<body bgcolor="#ffffff" text="#000000">

<div>
<center>
<b>Thank you <?php echo $name; ?></b>
<br>Your message has been sent
<p><a href="<?php print $continue; ?>">Click here to continue</a></p>
</center>
</div>

</body>
</html>

Best regards,
mbrodin

Graphicsgod
06-02-2007, 01:19 AM
I get this message:


The email () could not be sent.

With nothing in the brackets :(. Know why it's doing that?

It's weird that a simple email script wont go through. Especially since my login script works fine! Albeit it's using ASP files... I just can't get it to change data in the Microsoft database file :(.

http://www.idtagem.com/doctorsite/scripts/Login_test/

You think scripting this in ASP would yield better results?

Rob

Graphicsgod
06-02-2007, 01:23 AM
Oh and thanks for showing how to do first and last names!

Rob

Tau'ri
06-02-2007, 02:30 AM
There is also a PHP Form Mail Script at http://www.stadtaus.com/ that you may want to look at. It's a real simple but very powerful script Ralf has for free. I use it myself and it is very easy to customize.

Best Regards,
Jeff Hansen - (TeamJH) :) :rolleyes: :)

mbrodin
06-02-2007, 08:56 AM
I get this message:


&#239;&#187;&#191;The email () could not be sent.

With nothing in the brackets :(. Know why it's doing that?

It's weird that a simple email script wont go through. Especially since my login script works fine! Albeit it's using ASP files... I just can't get it to change data in the Microsoft database file :(.

http://www.idtagem.com/doctorsite/scripts/Login_test/

You think scripting this in ASP would yield better results?

Rob

I saw now that you must change $_POST['attn'] to $_POST['Attn'].
It's big different between UpperCase and LowerCase characters in this methods. It can be that made the Error message

&#239;&#187;&#191;The email () could not be sent.



Oh and thanks for showing how to do first and last names!

You welcome! ;)

Best regards,
mbrodin

mburt
06-02-2007, 03:35 PM
You think scripting this in ASP would yield better results?
ASP is no different in how it acts with the server then PHP is. They may be able to perform different functions, but the outcome of similar functions should be the same.

boxxertrumps
06-02-2007, 05:26 PM
Also the fact that ASP is an MS only format, so many servers that run on linux wont be able to handle it.

Graphicsgod
06-02-2007, 07:58 PM
Ok now the "Attention" field works. Can't believe I missed that, lol. But it still gives me the same error message :(.


The email ( General ) could not be sent.



Also the fact that ASP is an MS only format, so many servers that run on Linux wont be able to handle it.

Right, my server is windows based, as stated above. Linux is, from my understanding, better with PHP files. And windows servers are better with ASP. At least thats what I've been told from the books that I've read. Or did I misinterpret that?

Rob

Graphicsgod
06-02-2007, 08:00 PM
ASP is no different in how it acts with the server then PHP is. They may be able to perform different functions, but the outcome of similar functions should be the same.

True, true... Just trying to figure out why nothing gets sent :confused:.

Rob

thetestingsite
06-02-2007, 08:23 PM
True, true... Just trying to figure out why nothing gets sent

It could be a misconfiguration with the mail server. If you cannot get it to work with either PHP nor ASP, then this the case and you should contact your host immediately.

Hope this helps.

mbrodin
06-02-2007, 09:34 PM
Hi, Rob!

I think I have the prob! Try this code instead, this might resolve all problems!


<?php

// Are we going to send user to another location? True/False
$send_to_newPage = false;

$to = "Rob <mymail@gmail.com>";
$name = $_POST['first_name'] . " " . $_POST['last_name'];
$email = $_POST['email'];
$subject = $_POST['attn'];
$message = $_POST['text_box'];

$headers[] = "From: " . $name . " <" . $email . ">";
$headers[] = "MIME-Version: 1.0";
$headers[] = "Date: " . gmdate('D, d M Y H:i:s T', time() );

$subject = stripslashes($subject);
$body = stripslashes($message);


if( $send_to_newPage )
{

if( mail($to, $subject, $body, implode("\r\n", $headers)) )
{
header("Location: thanks.htm"); //Sends to New Page
}
else
{
echo "<p>An Error Occured, Please Resend<p>";
}

}
else
{

if( mail($to, $subject, $body, implode("\r\n", $headers)) )
{
echo "Mail (" . $subject . "), was successfully sent.";
}
else
{
echo "The email (" . $subject . ") could not be sent.";
}

}

$name = stripslashes($name);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>I.D. Tagem...Thanks!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- meta http-equiv="refresh" content="0;url=thanks.htm" -->

</head>
<body bgcolor="#ffffff" text="#000000">

<div>
<center>
<b>Thank you <?php echo $name; ?></b>
<br>Your message has been sent
<p><a href="<?php print $continue; ?>">Click here to continue</a></p>
</center>
</div>

</body>
</html>

Was this code helpfull?

Best regards,
mbrodin

Graphicsgod
06-03-2007, 10:22 PM
Nope same error as before :(.

I tried calling up Godaddy.com, and they recommended I spend an extra five bucks a month to have my own server instead of using the shared network that I have now. I figured it was all BS! ..Are they right, or just trying to get me to pony up more money?

Rob

thetestingsite
06-03-2007, 10:35 PM
Are they right, or just trying to get me to pony up more money?


Probably the latter. Anyways; as a test, try the following code to see if you get an email.



<?php
$to = 'you@domain.com'; //change to point to your email address

mail($to, 'Test Message From PHP Script', 'This is a test');
?>


That will show a blank page when you go to it; but after executing the script, wait a few seconds or so (for server lag) and then check your email. If you still get an error, or no error but no email then it is a problem with the mail server.

Hope this helps.

Graphicsgod
06-04-2007, 01:18 AM
Probably the latter. Anyways; as a test, try the following code to see if you get an email.

That will show a blank page when you go to it; but after executing the script, wait a few seconds or so (for server lag) and then check your email. If you still get an error, or no error but no email then it is a problem with the mail server.

Hope this helps.

Tried it and I get no error and no mail. I let it sit for about ten minutes, reloaded the page, tried again and waited for about ten minutes. Changed the email address to another one and did the same, still nothing.

So if there is a problem with the mail server, how would I word it so that Godaddy.com doesn't point me to a "different more costly plan" ;)?


Also heres my PHP details, if anyone is interested...

PHP page 1 (http://img108.imageshack.us/my.php?image=myphpinfopage1yl4.gif)

PHP page 2 (http://img108.imageshack.us/my.php?image=myphpinfopage2pk0.gif)

And PHP page 3 (http://img50.imageshack.us/my.php?image=myphpinfopage3pv6.gif)

Rob

boxxertrumps
06-04-2007, 03:32 AM
Linux is, from my understanding, better with PHP files. And windows servers are better with ASP.
No, linux cant use ASP because MS doesn't release any software for linux. A rule of thumb is to create scripts that work regardless of the OS it's run on, so PHP is always a better option than ASP.

Do you have a mail server at localhost, and what kind?

EDIT: tell them their mail server might be busted, you only noticed when testing a script you were writing for a freind.

thetestingsite
06-04-2007, 03:38 AM
No, linux cant use ASP because MS doesn't release any software for linux.

However, you can get Chili-ASP or Apache::ASP and it will run ASP and ASP.net scripts. Just depends on the distro of Linux and whether you run Apache web server or not.



Do you have a mail server at localhost, and what kind?


If you look at the phpinfo in the links posted above, it shows that it is "supposedly" set up at localhost; however, this may not be the case (if they didn't set up the server correctly). Anyways, tell them to check all of the settings on the mail server because you are unable to send emails using a simple PHP script.

Graphicsgod
06-04-2007, 08:09 PM
Ok I gave them a call and they said everything "looked" ok on there end. They took a look at the email.php file, I created, and said to create another email server address and use that to test. And after an hour, and it doesn't work, to call them back.

I also came across a section of my account that says "You currently have no SMTP Relay accounts. Click here to purchase one." I wouldn't need one of these would I?!? I hope not, since it's another five dollars extra a month :(. I also have no "Email Forwarding", but don't believe that will solve my problem.

I'll try testing it after an hour and post any results...

Rob

djr33
06-04-2007, 11:25 PM
If you want a big more info on configuration, you can run this code--

<?php phpinfo(); ?>

and this for a couple more precise checks:

<?php
if (function_exists('mail')) {
echo "mail() function exists!\n";
if (mail('your@email.com', 'Test Message From PHP Script', 'This is a test')) {
echo "Successfully sent, or so the server thinks...";
}
else {
echo "Sending the email failed.";
}
}
else echo "mail() doesn't exist";
?>

The first will check the server configuration and allow you to check all the setup. It will likely show whether mail is enabled or not.

The second will check first if the function mail() even exists and if so attempt to send an email. When it attempts this, it will check if the mail worked or not (according to the script), then tell you what it thinks happened. If it says it failed, then that makes sense. If it does say it worked, however, something else is probably going on.

Graphicsgod
06-05-2007, 12:12 AM
Nope still nothing. Not really wanting to go back through Godaddy.com's tech support. And try to explain over and over again what I want to do. And get a "I'm not sure I follow you." type answer. Or "That will cost you .... dollars, can I sign you up!"... *sigh*


As for the first one djr33, I've already done that. Look above, I posted links to pictures of the output of the PHP info.

And as for the second I get:

mail() doesn't exist

This can't be good right, lol? Don't know what to tell Godaddy.com, that will get through their heads to turn this on, or make it happen without costing me more money :(.


I also came across a section of my account that says "You currently have no SMTP Relay accounts. Click here to purchase one." I wouldn't need one of these would I?!? I hope not, since it's another five dollars extra a month . I also have no "Email Forwarding", but don't believe that will solve my problem.

So it looks like I might have to pay for the SMTP account on additional to my server and hosting costs :mad:?!?

Rob

alexjewell
06-05-2007, 12:18 AM
Yeah, means the mail() function doesn't exist in the first place. To me, that's more than just setting up a SMTP account...

If I were you, I'd purchase the SMTP account. However, I would only after making sure it would solve the problem. As of right now, I'm not.

Graphicsgod
06-05-2007, 01:21 AM
Yeah, means the mail() function doesn't exist in the first place. To me, that's more than just setting up a SMTP account...

Thats what I figured when I last was poking around my account to see what I was doing wrong.

Do you know what I could tell these people that wont cause me to have to break it down to kindergarten terms?

Beacuse every time I call them they either say "That costs money.", "I don't understand what your trying to do?", or "Why are you doing that?".



If I were you, I'd purchase the SMTP account. However, I would only after making sure it would solve the problem. As of right now, I'm not.

Well if you feel it wont work.. why do it? I'd hate to purchase something, and then go through the process of removing it later on.

I'm starting to get annoyed by my hosting provider. When I first signed up and told the guy what I wanted to do, he was like "Sure thats no problem! Just FTP all your files and it should work.". HA!

Rob

thetestingsite
06-05-2007, 01:31 AM
Well, if you wanted to I could host your PHP script (the one that sends the email) or you could also look at Remote Form Processing services. Let me know if you would like me to host it for you though.

Graphicsgod
06-05-2007, 06:24 AM
Well, if you wanted to I could host your PHP script (the one that sends the email) or you could also look at Remote Form Processing services. Let me know if you would like me to host it for you though.

As tempting as that may be, I'd hate to harass you every time I need to make changes to a file or what have you. I'm currently looking at one of those free PHP file hosting services. Not sure if it will benefit or create more problems. That will do till I figure out if I can get Godaddy.com to do what I need or go else where :(.

You'd think if your paying money for a server, that you should be able to use it to do simple scripts and html... Just as long as your not abusing it. I just don't get it :rolleyes:.

Rob

thetestingsite
06-05-2007, 06:33 AM
You'd think if your paying money for a server, that you should be able to use it to do simple scripts and html... Just as long as your not abusing it. I just don't get it :rolleyes:.


That only goes for a Dedicated Server and not a Shared one in the hosting world.

Graphicsgod
06-05-2007, 07:13 AM
I tried this one free hosting site.. Seems to give me the same problems. I installed PHP and everything and it seems like it's ok, but the same errors appear.

http://graphicsgod.phpnet.us/

Feel free to take a look at it. If you want access, let me know. I could care less since it's free and I'm just testing it ;).

Rob

Graphicsgod
06-05-2007, 07:17 AM
That only goes for a Dedicated Server and not a Shared one in the hosting world.

Yeah I talked to a level 2 tech at Godaddy.com (after going crazy talking to the level 1s and CSR's). And he said I would need to upgrade my server to a "dedicated" one :(. I think I got this same info before, when discussing this. That means more money on top of what I'm already paying a month. Just to do php mail files.

Rob

alexjewell
06-05-2007, 02:07 PM
Ha, yeah. There's better ways to go about this than paying more money. Now, the solutions are more work than just paying more money, and it wouldn't be a great idea to do these for the rest of your web design career. Ha. I'm actually kind of going through the same thing, with my mail() function not working at all. Thank God I have clients who have servers that do support it and graciously allow me to have files on them.