Forum Moderators: coopster
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 is right, try a simple mail() test first. Also, check your mail configuration directives [php.net].
<?
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.
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.
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]
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
$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
<?
$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]
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
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
Do you have code templates that I can use with SMTP so I can get the contents of a form emailed to me?
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.