Forum Moderators: coopster
Can't seem to find the problem, could anyone help?
all info in $message is printed on one line (when I print to screen to debug) as is the other info, don't know if that is relevant. Information is sent to the script from the "POST" method and the form works fine (at least is used to!).
The end is going to be a if good then go, else print error, I have the code but am only concerned with getting the mail() part to work (at least right now!)
Here is the code::
<?php
// configure redirect
$redirect = "http://www.anydomain.com/contact/thanks.html";
$subject = "Website Information Request";
// check to see if a sales rep selection was made if error send to me
if ($salesrep =="") {
$mailingto = "webmaster@anydomain.com";
} else {
$mailingto = "$salesrep@anydomain.com";
}
// if user entered an email address use it else from the
if ($email =="") {
$from = "From: webserver@anydomain.com";
} else {
$from = "From: $email";
}
// create message body
$message = "";
foreach($HTTP_POST_VARS as $key => $value)
{
$message .= $key ." : " .$value ."/n";
}
mail($mailingto, $subject, $message, $from);
//header("Location: $redirect");
//} else {
//echo('<p>We are sorry, our server is temporarily unable to send mail.</p>');
//}
?>
Here is some server info from phpinfo()::
PHP Version 4.2.3
sendmail_path /usr/bin/sendmail -t -i
any other info needed just ask..
A) the script sends no email,
B) the web page freezes on loading (myparseandsend.php) when the mail(*****) is not commented out.
It seams (after I split it in two) that the form works, it submits correctly to this script, the if() statements function correctly, and if I print() all the information to screen I get the expected information. but as soon as I add the mail() function I get
1) blank white web page, like the script is waiting to finish and output something and it just sits there.
2) I have gotten some other 404 or other, but that might have been me debugging at 3AM
Have you tried just sending a simple mail to yourself? (not necessarily in this script)
$ret = mail("you@yourdomain.com","Testing Mail","This is a Test");
if ($ret) {
echo "<p>email was sent!";
} else {
echo "<p>it bombed...";
}
if that works then look at the values of your vars again and see if that is what is choking the mail function.
Gona love this,
If I put that script in just as it is and forget to put my acuall email in it pops right up with "email was sent!"
If I take the 10 second to change the email to an acuall email it hangs for over a minute then I get "email was sent!"
But never get email.
BTW I have no access that I know of the sendmail logs for www.greatwebhostwithissue.com, I even have a path for a php log but no file.
Is this starting to sound like a webhost related issue?
so if it's a webhosters issue with phpmailer you maybe can go around that... ;)
Good Code ------
<?php
// configure redirect and subject
$redirect = "http://www.domain.com/thanks.html";
$subject = "Website Information Request";
// if you have a selection named salesrep
//(mine has you pick a county and the value is the email user name)
//the value should be just the info before the @domain.com
//this prevents harvesting
if ($salesrep =="") {
$mailingto = "info@domain.com"; //if no value then send to default user
} else {
$mailingto = "$salesrep@domain.com";
}
// if web user entered an email address use it else from the webserver@
// if you have a field named email in your form and it is filled out
// the generated email will be from the user
// you will want to validate the email format first on the html side!
// or you can validate here if you want to figure it out
if ($email =="") {
$from = "From: webserver@domain.com\r\n";
} else {
$from = "From: $email\r\n";
}
// create message body
$message = "";
foreach($HTTP_POST_VARS as $key => $value)
{
$message .= $key ." : " .$value ."\n";
}
$ret = mail($mailingto, $subject, "Information was requested by $realname from our website \r\n $message", $from);
if ($ret) {
header("Location: $redirect");
} else {
echo('<p>We are sorry, our server is temporarily unable to send mail.<br>Please call us at blah blah blah</p>');
}
?>
i love the difference between good and right:
somtimes it is just nice to have an extra set of eyes let you know you are not seeing things and to help point me in the right direction:
so well, i also welcome you (maybe with permission of jatar_k) to webmastworld!
enjoy your stay here and welcome you back!