why the mail can not work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lancet2003
Forum Newbie
Posts: 20
Joined: Sat Aug 09, 2003 11:29 pm

why the mail can not work?

Post by lancet2003 »

The following is the code of text.php

Code: Select all

<HTML>
<HEAD>
<TITLE>E-Mail Form</TITLE>
</HEAD>
<BODY>
<FORM action="hidden.php" method="POST">
Your Name: <INPUT type="text" name="name"><br><br>
Your E-Mail Address: <INPUT type="text" name="email"><br><br>
Message:<br>
<textarea name="message" cols=30 rows=5></textarea><br><br>
<INPUT type="submit" value="Send Form">
</FORM>
</BODY>
</HTML>

the following is the code of hidden.php

Code: Select all

</head>
<body>
<?php
print "Thank you, <b>$_POST&#1111;name]</b>, for your message!<br><br>\n\n";
print "Your e-mail address is: <b>$_POST&#1111;email]</b><br><br>\n\n";
print "Your message was:<br><br>\n\n";
print "$_POST&#1111;message] <br><br>";

//start building the mail string
$msg = "Name:     $_POST&#1111;name]\n";
$msg .= "E-Mail:   $_POST&#1111;email]\n";
$msg .= "Message:  $_POST&#1111;message]\n";

//set up the mail
$recipient = "yuping-wang@tamu.edu";
$subject = "Form Submission Results";
$mailheaders = "From: My Web Site <defaultaddress@yourdomain.com> \n";
$mailheaders .= "Reply-To: $_POST&#1111;email]\n\n";

//send the mail
mail($recipient, $subject, $msg, $mailheaders) or print " could not send mail";
?>
</body>
</html>

when I run the program, why it always shows that "could not send mail"
Thanks
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

instead of the " or " statement, use:

Code: Select all

<?php
if(!mail($recipient, $subject, $msg, $mailheaders))
{
// Unable to send
} else {
// Able to send
}
?>
Image Image
lancet2003
Forum Newbie
Posts: 20
Joined: Sat Aug 09, 2003 11:29 pm

Post by lancet2003 »

if(!mail($recipient, $subject, $msg, $mailheaders))
{
print "Unable to send" ;
} else {
print "Ok";
}


Then always shows:
" Thank you, aa, for your message!

Your e-mail address is: bbb

Your message was:

ccc

Unable to send "
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

is the mail section of the php.ini configured?
[mail function]
; For Win32 only.
SMTP = localhost

; For Win32 only.
sendmail_from = me@localhost.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
try it without the additional mail headers. It might be that the MTA accepts neither the unknown From: nor the unkown reply-to: address
Post Reply