Forum Moderators: coopster

Message Too Old, No Replies

PHP Email Form not sending mail

         

Betty Patten

4:17 pm on Apr 11, 2003 (gmt 0)

10+ Year Member



Hi there,
Another new-bie to PHP....
I have trawled through many pages of code, many topics and many questions, but I cannot seem to make ANY! of my forms work. I simply want the user to complete a form, to click submit and for the details of that form to be sent in the background to an admin person at the other end.

I have robbed and tried so much code now that I am lost and don't know where to begin. I copy here the most recent borrowings from another user on this site (thank you for contributions) which I believe should solve some of the problems.

The discrepency is that IF Global variables are turned off, by database connected pages shouldn't work, should they?

I have stripped everything out here and included the original .htm file:

<form method="post" action="question.php">
Requested by: <input type="text" name="by" size="40">

Address: <input type="text" name="address" size="40">

County: <input type="text" name="county" size="40">

Postcode: <input type="text" name="postcode" size="40">

Email: <input type="text" name="email" size="40">

Question or Comments: <input type="text" name="comments" size="40">

<input type="submit" name="Ask" value="Ask our Expert!">
</form>

<?php

echo "<PRE>_POST: ";
print_r ($_POST);
echo "</PRE>";

$today = date("F j, Y, g:i a");

//Get the contents of form
$by = $_POST['by'];
$address = $_POST['address'];
$county = $_POST['county'];
$country = $_POST['country'];
$postcode = $_POST['postcode'];
$email = $_POST['email'];
$comments = $_POST['comments'];

$message = "Revision request submitted on $today\n
\n
Requested by: $by\n
Address: $address\n
County: $county\n
Country: $country\n
postcode: $postcode\n
Email: $email\n
\n
Comments: $comments \n";

$to = "name@domain.com";
$from = "name@domain.com";
$subject = "Revision Request - $today";

mail($to,$subject,$message);

print "done!";
?>

AND it doesn't work! ARGGGHHH
The site is a charity site and I am trapped doing more work on it that paying clients, as I haven't scripted in PHP before and am steadily going mad. :(

Can anyone see what is going on?
I will happily send chocolates to whoever can point me in the right direction.
Cheers
Betty

[edited by: jatar_k at 4:37 pm (utc) on April 11, 2003]
[edit reason] trimmed out unnecessary html [/edit]

jatar_k

4:29 pm on Apr 11, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld Betty_Patten,

Are you getting any error messages? When it misbehaves, what happens? Big zero? Does it print "done!" but no email?

I can see some possible probs but I was wondering about these questions as well.

jatar_k

4:48 pm on Apr 11, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try this

<?
echo "<PRE>_POST: ";
print_r ($_POST);
echo "</PRE>";

$today = date("F j, Y, g:i a");

$message = "Revision request submitted on $today\r\n\r\n";
$message .= "Requested by: $_POST['by']\r\n";
$message .= "Address: $_POST['address']\r\n";
$message .= "County: $_POST['county']\r\n";
// there isn't even a country field in the html you posted but I left it in
$message .= "Country: $_POST['country']\r\n";
$message .= "postcode: $_POST['postcode']\r\n";
$message .= "Email: $_POST['email']\r\n\r\n";
$message .= "Comments: $_POST['comments'] \r\n";

$to = "name@domain.com";
$from = "From: $_POST['email']\r\n";
$subject = "Revision Request - $today";

mail [php.net]($to,$subject,$message,$from);

print "done!";
?>

I switched from \n to \r\n since, I am guessing, you will use an ms mail client I don't think \n works they use \r\n for newlines.

Betty Patten

8:17 pm on Apr 13, 2003 (gmt 0)

10+ Year Member



Thanks for these, I will try them in the morning. No error messages with most of the attempts, nothing at all to let me know what is going on at all. Only a blank page with nothing on it. This is the most frustrating part of it all. I have tried other code to send back to the page the variables to check they were working, and that seems ok (didn't do that here, obviously, otherwise would have spotted the missing 'Country'!). Anyway, will give this a fresh shot first thing in the morning, using your suggestions and see how I get along.
Many thanks for taking the time to respond.
Will truncate .htm code in the future.
Big cheers,
Betty

Longhaired Genius

10:18 pm on Apr 13, 2003 (gmt 0)

10+ Year Member



If you don't feel you HAVE to do this yourself, as a programming exercise, why not use phpformmail from www.boaddrink.com

It can be set up in minutes and it works like a dream.