Forum Moderators: coopster

Message Too Old, No Replies

PHP Form email?

         

buttsy00

2:10 am on Aug 17, 2004 (gmt 0)

10+ Year Member



Hi everyone I am having trouble with this script that I am using to email me the contents of a form...

I am not getting any errors what so ever and when the form is filled out and submit is hit it takes me to the correct thank you page but I am not getting the emails?

Here is the script:

<?

// ------------- CONFIGURABLE SECTION ------------------------

$mailto = 'me@example.com.au' ;
$subject = "Warehouse Order Form" ;

$formurl = "http://www.example.com.au/html/contactus2.php" ;
$errorurl = "http://www.example.com.au/html/error.php" ;
$thankyouurl = "http://www.example.com.au/html/thanks.php" ;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) ¦¦ empty($email) ¦¦ empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}

$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\nReply-To: \"$name\" <$email>\nX-Mailer: chfeedback.php 2.02" );
header( "Location: $thankyouurl" );
exit ;

?>

Here is my html code in the page where the form is:

<form action="http://www.example.com.au/html/feedback.php" method="post">
<table border="0" cellpadding="8" cellspacing="8" summary="feedback form">
<tr><td>Name:</td><td><input type="text" name="name" size="25" /></td></tr>
<tr><td>Email address:</td><td><input type="text" name="email" size="25" /></td></tr>
<tr>
<td colspan="2">
Comments<br />
<textarea rows="15" cols="45" name="comments">
</textarea>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Send Feedback" />
</td>
</tr>
</table>
</form>

Any help would be appreciated guys as I am only new to PHP...

[edited by: jatar_k at 2:15 am (utc) on Aug. 17, 2004]
[edit reason] generalized urls [/edit]

Timotheos

3:43 pm on Aug 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm... nothing stands out to me.

What happens if you just hard code a simple mail message
mail("me@example.com", "TEST", "This is a test");

coopster

8:17 pm on Aug 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, buttsy00!

Timotheos is right, try a simple mail() test first. Also, check your mail configuration directives [php.net].

buttsy00

9:22 pm on Aug 17, 2004 (gmt 0)

10+ Year Member



Where do I enter then mail() script? In the html page where the form is or in the php script?

Sorry for being ignorant but I am very new to php...

ergophobe

9:43 pm on Aug 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



just create a file called "mailtester.php" that has nothing on it except this:

<?
if (mail("me@example.com", "TEST", "This is a test"))
{
echo "mail successfully sent.";
}
else
{
echo "Houston, we have a problem";
}
?>

Obviously, you will want to put in a valid e-mail address that you can actually check instead of "me@example.com".

Now just point your browser h**p://domain/mailtester.php and it should send a mail or show an error.

Timotheos

9:43 pm on Aug 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd just comment out your existing one
//mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\nReply-To: \"$name\" <$email>\nX-Mailer: chfeedback.php 2.02" );

and below it put your test.

buttsy00

10:26 pm on Aug 17, 2004 (gmt 0)

10+ Year Member



ergophobe I did what you said and it came up "mail successfully sent." but I still haven't received any email?

What does that mean the problem could be? Something to do with my ISP?

Oras

1:33 pm on Aug 18, 2004 (gmt 0)

10+ Year Member



Hi buttsy00 ...
Try to replcae the $_POST['....'] by:
$HTTP_POST_VARS['....']

for Example:
$name=$HTTP_POST_VARS['name'];
$email=$HTTP_POST_VARS['email'];
...etc.
& I'm sure that this will work :)
Regards
Oras

ergophobe

3:47 pm on Aug 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oras,

Welcome to WebmasterWorld.

Unfortunately, since he's currently hardcoding in the address and still not receiving the mail, your solution won't help (and if he is on a version of PHP installed any time in the last few years, it won't make any difference).

The mail() command is returning true, so that should mean that it successfully connected to the SMTP server and sent something out, but it didn't arrive.

Is it possible that your ISP who provides the email address you're sending to has some sort of spam filtering in place? It may want a valid address in the from field, in which case, your mail should look like this

$to = "address.to@send.to";
$subject = "Mail test";
$msg = "Testing my mailer";
$headers = "From: " . $this->from_name . " <" . $this->from_addr . ">\r\n";
$headers .= "Reply-To: " . $this->from_name . " <" . $this->from_addr . ">\r\n";

if (mail($to, $subject, $msg, $headers))
{ ... etc

If it still doesn't work, try a simple "\n" instead of "\r\n" at the end of the headers lines.

buttsy00

6:44 am on Aug 19, 2004 (gmt 0)

10+ Year Member



Oras I tried what you suggested but unfortunately it didn't work...

Ergophobe,

There is a good possibility that my ISP has some sort of spam filter...

I am sorry for being ignorant but what is a valid address? My email I am trying to send the form to is user@example.com.au

If possible could you send me exactly what you have asked me to try with my "valid address" in there already so I can just copy and paste?

I really appreciate the help guys...

[edited by: coopster at 1:35 pm (utc) on Aug. 19, 2004]
[edit reason] generalized email address [/edit]

Timotheos

7:57 am on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was here so I just sent you an email to you with that script.

Might be worth contacting your web host as well to see what they think.

Tim

ergophobe

2:03 pm on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




my "valid address"

The address that you normally use to send/receive mail. One that you are certain works and is permitted to send mail to the address you are sending to/from. It sounds like that's what you're doing. Did you get Timotheos' email?

By default, if you don't add the "from" the mail is sent from "nobody@domain" because the PHP process is run by "nobody". It's fairly common to have it filtered out for that reason. That's why I suggested trying the "from" and "reply to" headers (with valid addresses, preferably on the same server as the one sending the mail).


My email I am trying to send the form to is user@example.com.au

And do you have the same in the "from" and "reply to" fields? Try the same one for starters.

Tom

buttsy00

11:17 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



Yes I received Timotheos email... Where did you esnd that from?

What code exactly do I need to add to my script?

Could you post the whole script with what I need to add in there please?

Thanks again guys this is really appreciated!

Timotheos

11:50 pm on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I simply used the code in msg #5.

<?
if (mail("me@example.com", "TEST", "This is a test"))
{
echo "mail successfully sent.";
}
else
{
echo "Houston, we have a problem";
}
?>

I would suspect a problem with your mail server.

buttsy00

2:11 am on Aug 20, 2004 (gmt 0)

10+ Year Member



ergophobe,

can you send me the complete code I need like below with the from and reply to headers etc included so I can test what you were saying?

<?
if (mail("me@example.com", "TEST", "This is a test"))
{
echo "mail successfully sent.";
}
else
{
echo "Houston, we have a problem";
}
?>

ergophobe

2:25 am on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I made a little mistake when I posted before - pasted from my mailer class, which has stuff you don't want:

$to = "email_to@domain.com";
$subject = "Mail test";
$msg = "Testing my mailer";
$headers = "From: email_from@domain.com\r\n";
$headers .= "Reply-To: email_from@domain.com\r\n";

if (mail($to, $subject, $msg, $headers))
{

... and as above ...

obviously, you need to replace email_to@domain.com and email_from@domain.com with valid addresses. Since Timotheos' try went through without the extra header info, though, I think he's right that you may just not be getting the mail server to send on your machine.

In your php.ini file, can you turn error reporting up to E_ALL? I can't remember whether failure to send a mail sends a notice, warning or error.

Tom

buttsy00

6:08 am on Aug 20, 2004 (gmt 0)

10+ Year Member



I just tried this script....

<?
$to = "me@example.com.au";
$subject = "Mail test";
$msg = "Testing my mailer";
$headers = "From: me@example.com.au\r\n";
$headers .= "Reply-To: me@example.com.au\r\n";

if (mail($to, $subject, $msg, $headers))
if (mail("me@example.com.au", "TEST", "This is a test"))
{
echo "mail successfully sent.";
}
else
{
echo "Houston, we have a problem";
}
?>

and it came up "mail successfuly sent" but once again I didn't receive the email...

I have contacted my ISP and they asked me if the script requires certain mail programs to be running on the server? As far as I know it doesn't... what do you guys think?

[edited by: coopster at 12:02 pm (utc) on Aug. 20, 2004]
[edit reason] generalized email address [/edit]

Timotheos

8:36 am on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where are you running this script from? Is is a shared server? Is it a dedicated server? Or your computer at home?

The mail function requires sendmail (or qmail or postfix) to be running on the server.

ergophobe

2:06 pm on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



AFAIK, it would not return "true" if it couldn't find a mail server. I don't have a mail server on my development workstation and it just returns false. It also returns at least a notice or warning if you have error reporting set to E_ALL.

Buttsy, put the following at the very top of your script and try it again

error_reporting [php.net](E_ALL);

Do you get any error messages when you run the script?

Tom

buttsy00

12:17 am on Aug 25, 2004 (gmt 0)

10+ Year Member



Timotheos, i am running on a Linux server...

ergophobe, I added error_reporting(E_ALL); to the top of my script but it went through as "mail successfully sent" again but still no email?

What should I do now?

buttsy00

1:12 am on Aug 25, 2004 (gmt 0)

10+ Year Member



My ISP contacted me and said they have neither Postfix or Sendmail currently running on the server, and they don't have them running due to some security issues...

They asked me if it's possible to just specify an SMTP server for the sending of mail?

Timotheos

4:16 pm on Aug 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wow, I'm really surprised that you are not getting any error messages. Since you are hosting with your ISP then you more then likely will not have any control over your php.ini file.

You might want to consider then taking a different tack and look at phpmailer [phpmailer.sourceforge.net]. I've never used it but it's more flexible then php's mail function. Look at the page and you'll see an example of how you can specify your own SMTP server, name, password and send out mail from php that way. Might even work out better for you in the long run.

Tim

buttsy00

2:24 am on Aug 27, 2004 (gmt 0)

10+ Year Member



when i run the phpinfo() function i get the following:
sendmail_path - /usr/sbin/sendmail -t -i
sendmail_from - me@localhost.com (should this be changed to my email address?) Could that be my problem?

Do you have code templates that I can use with SMTP so I can get the contents of a form emailed to me?

coopster

2:00 pm on Aug 28, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




sendmail_from - me@localhost.com (should this be changed to my email address?) Could that be my problem?

No. This is your problem.


My ISP contacted me and said they have neither Postfix or Sendmail currently running on the server, and they don't have them running due to some security issues...

Your ISP (assuming this is your hosting provider) is telling you that they aren't running a mail server that you can use. They are telling you to use a different mail server, somewhere else. Timotheos has pointed you toward a possible solution in phpmailer, but only if you have another SMTP (sending of email) server somewhere else that you can use.