Forum Moderators: coopster

Message Too Old, No Replies

Help with mail() and php

problems sending form results

         

scotttyz

5:02 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



I am having a bear of a time with a new script, I am replacing a recently failed formail.cgi and the forms are down

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..

scotttyz

5:10 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



PS: I have tested both if() statments and they work with the form relayed info

jatar_k

5:48 pm on Jul 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld scotttyz,

What is the error or how is it misbehaving?

oh and this
$message .= $key ." : " .$value ."/n";

should be
$message .= $key ." : " .$value ."\n";

I would also add
$from = "From: webserver@anydomain.com\r\n";

scotttyz

5:59 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



Thanks fot the Welcome (back acually but it has been a while) jatar_k,

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

scotttyz

6:09 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



O btw, to answer your next question (i think), I had inserted a print "i am here";
and a print "end of script";
at respective points to verify what was happening, nothing unless I commented out the mail()

jatar_k

6:10 pm on Jul 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have I mentioned I hate mail, always causes problems

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.

jatar_k

6:11 pm on Jul 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Also, any access to the maillog to see if sendmail will tell you what it doesnt like? Or if it even knows you were trying to get a hold of it.

scotttyz

6:43 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



I can agree on the header to your email (hating mail)

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?

hakre

6:51 pm on Jul 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



do you have access to the smtp server there? then mayve phpmailer [phpmailer.sourceforge.net] can help. you can use smtp directly then.

so if it's a webhosters issue with phpmailer you maybe can go around that... ;)

scotttyz

6:56 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



hating mail

hating mail server upgrades

hating webhost missing files

be right back......

scotttyz

7:30 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



Well the issue as on the webhost side, they missed a configuration update, I am posting the code that worked for future use by anyone

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>');
}

?>

scotttyz

7:36 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



THANK YOU jatar_k and hakre!

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:

Scotttyz

if ($time=="not enough") {
echo "crazy"
} else {
echo "broke"
}

hakre

11:05 pm on Jul 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



welcome to webmasterworld [webmasterworld.com], scotttyz!

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!

scotttyz

11:26 pm on Jul 23, 2003 (gmt 0)

10+ Year Member



I am just glad no one pointed me in the left direction