Page 1 of 1

Email form questions

Posted: Wed Sep 13, 2006 8:51 pm
by Leao
Hi,

I'm using the attached PHP mail fuction for an email form on my site that retrieves variables from a Flash .swf file. The code works and emails are sent, but I know the code could be improved. For example, my web host says that I need to use the following FROM syntax within the Mail () function: "-fuser@domain.com". I'm not doing this at the moment as when I try to do this the email I receive includes within its actual message the text: -fdonotreply@stpatrickscommunity.org
Reply-To:
X-Mailer: PHP/4.4.1


Also at php.net it suggests adding the following code in order to stop mail providers such as Hotmail marking the php-generated e-mails as spam.

Code: Select all

'Return-Path: ' . $sender_address . "\n"
I don't understand where to include this line of code. It's important that my code is Hotmail friendly as the email is being sent to an email address that subsequently forwards to my Hotmail account.

Any help would be greatly appreciated. I'm anxious that this mail function is as good as it can be.

Many thanks,

Leo

Code: Select all

<?
$to = 'donotreply@stpatrickscommunity.org';

$subject = 'Message for the St. Patricks Community';

$body = "You have received a message via the St. Patrick's Community website. The details of the message are listed below...\n\nName: $name\nEmail: $email\n\nMessage: $message";

$body = wordwrap($body, 70);

$headers = 'From: donotreply@stpatrickscommunity.org' . "\r\n" .
   "Reply-To: $email" . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $body, $headers);

?>

Posted: Wed Sep 13, 2006 9:25 pm
by gkwhitworth
I am not sure....but I think that it looks pretty good to me. And I always say...if it aint broke...don't fix it, wait I don't say that.

-
Greg

Posted: Wed Sep 13, 2006 9:31 pm
by Leao
It is a bit broke. The message never reaches my Hotmail account even though the email account the PHP sends to is set-up to forward to my Hotmail. I have another almost identical form (see below) that does manage to reach my Hotmail account. I don't understand why one works and the other doesn't. The only difference between the two is that the one below has a different subject line and more variables.

Cheers - Leao

Code: Select all

<?
$to = 'donotreply@stpatrickscommunity.org';

$subject = 'School retreat booking request';

$body = "You have received a request for a school retreat via the St. Patrick's Community website. The details of the request are listed below...\n\nSchool: $school\nAddress: $address\nPhone: $schoolsphone\nFax: $schoolsfax\n\nTeacher: $teacher\nPhone/mobile: $teachersphone\nEmail: $email\n\nRetreat option: $retreatoption\nAge range: $agerange\nNo. of pupils: $noofpupils\nGender: $gender\n\nPreferred dates:\nDate 1: $date1\nDate 2: $date2\n\nMessage (optional): $message";

$body = wordwrap($body, 70);

$headers = 'From: donotreply@stpatrickscommunity.org' . "\r\n" .
   "Reply-To: $email" . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $body, $headers);

?>

I think....

Posted: Wed Sep 13, 2006 10:52 pm
by gkwhitworth
Hey I built a form and used your php script... I got the following errors.... I hope this helps:

Code: Select all

Notice: Undefined variable: email in D:\users\gkwinspired.com\development\sendmail.php on line 6

Notice: Undefined variable: message in D:\users\gkwinspired.com\development\sendmail.php on line 6

Notice: Undefined variable: email in D:\users\gkwinspired.com\development\sendmail.php on line 13

I didn't change a thing except the email address (hotmail)

I also noticed that you don't get the variables anywhere in your script either by $_POST or $_REQUEST, none?

Kinda wierd. You may want to try that.

--
Greg

Posted: Wed Sep 13, 2006 10:59 pm
by Leao
Hi, thanks gkwhitworth. To be honest I'm really very new to PHP and am rather confused. What are you suggesting I should change?

Cheers,

Leo

Posted: Wed Sep 13, 2006 11:59 pm
by gkwhitworth
I am not really saying that you should change anything.... I am just saying that it would be a good idea to place the values into variables...

To be honest, I am quite a newb myself...I have just dealt with forms a lot lately. Anyways, this is how I would lay my form php script out:

Code: Select all

<? session_start()

if (!isset ($_REQUEST['school'])) {
echo "Please fill in your school"
}

$school = $_REQUEST['school'];
$address = $_REQUEST['address'];
$schoolsphone = $_REQUEST['schoolsphone'];
$schoolsfax = $_REQUEST['schoolsfax'];
$teacher = $_REQUEST['teacher'];
$teachersphone = $_REQUEST['teachersphone'];
$email = $_REQUEST['email'];
$retreatoption = $_REQUEST['retreatoption'];
$agerange = $_REQUEST['agerange'];
$noofpupils = $_REQUEST['noofpupils'];
$gender = $_REQUEST['gender'];
$date1 = $_REQUEST['date1'];
$date2 = $_REQUEST['date2'];
$message = $_REQUEST['message'];

$to = 'donotreply@stpatrickscommunity.org';

$subject = 'School retreat booking request';

$body = "You have received a request for a school retreat via the St. Patrick's Community website. The details of the request are listed below...\n\nSchool: $school\nAddress: $address\nPhone: $schoolsphone\nFax: $schoolsfax\n\nTeacher: $teacher\nPhone/mobile: $teachersphone\nEmail: $email\n\nRetreat option: $retreatoption\nAge range: $agerange\nNo. of pupils: $noofpupils\nGender: $gender\n\nPreferred dates:\nDate 1: $date1\nDate 2: $date2\n\nMessage (optional): $message";

$body = wordwrap($body, 70);

$headers = 'From: donotreply@stpatrickscommunity.org' . "\r\n" .
   "Reply-To: $email" . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $body, $headers);

?>
This actually calls the user's inputs into variables making it so you can call them up later...I also put in an isset and a session, if you don't know what those do....let me know.
--
Greg