Log in

View Full Version : mail and alert in PHP



devil_vin
02-15-2008, 09:22 AM
Hi,guys! I have a PHP script to send mail and prompt out alert if successfully sent.However,the alert is not displayed and all the form value become blank.How can I display alert without having a blank page?

Secondly,the mailing script seems having some flaws,if form submitted,the previous sent form will be sent once again into the mailbox.What went wrong actualy?Thanks for you guys help!




<?php

$email = $_GET[email];
$mailto = "yourmail@mail.com";
$mailsubj = "Enquiry sent by visitor";
$mailhead = "From: $email";

reset ($_GET);

$mailbody = "You have an enquiry from website:\n";

while (list ($key, $val) = each ($_GET)) {
if($key != 'submit')
$mailbody .= "$key : $val\n"; }

ini_set("SMTP",mail.yourmailserver.com.my);
ini_set("smtp_port",25);
ini_set("sendmail_from",$email);

$javascript = "<script type=\"text/javascript\">";

if (mail($mailto,$mailsubj,$mailbody,$mailhead)) {
$javascript .= 'alert(\'Thank you for your enquiry, we shall contact you soon.\')';
} else {
$javascript .= 'alert(\'Email cannot be delivered.\')';
}
$javascript .= '</script>';

?>






<FORM NAME="enquiry" ACTION="<?php echo htmlentities($HTTP_SERVER_VARS['PHP_SELF']); ?>" METHOD="GET">

fileserverdirect
02-17-2008, 01:48 AM
I can see one problem, you never executed $javascript It is only a variable. At the end of your document put:

echo $javascript;
And the reason that all the feilds become blank is that you are basicly refreshing the page. Not shure why it is not sending the email, but add this, just to check to see if it is going through (in bold):


if(mail($mailto,$mailsubj,$mailbody,$mailhead)) {
echo "MAIL WENT THROUGH";
$javascript .= 'alert(\'Thank you for your enquiry, we shall contact you soon.\')';
} else {

Not shure why it does what you said but.......
Hope this helps,

TimFA
02-17-2008, 04:13 AM
I believe he wants it to be like an Ajax request, so it never refreshes. File, just curious, why do you spell sure "shure"? :)

fileserverdirect
02-17-2008, 04:02 PM
I type very fast...

Twey
02-17-2008, 04:25 PM
You should get a recent browser, most of them have spell-check features nowadays.