PDA

View Full Version : PHP Email Form



massive3215
November 18th, 2005, 02:49 PM
I'm adding one to Kirupa's tutorial on the Flash and PHP email form. Instead of the generic message field I have three seperate fields (address, phone number, and company) that I all want put in the body of the email, preferably double spaced between each entry. The 3 input variable names are address, phone, and company. Right now it's not working correctly. I don't know PHP so I'm guessing this is pretty simple for someone to correct. Thanks!



<?php
/************************************************** *\
* PHP 4.1.0+ version of email script. For more
* information on the mail() function for PHP, see
* http://www.php.net/manual/en/function.mail.php
\************************************************* **/


// First, set up some variables to serve you in
// getting an email. This includes the email this is
// sent to (yours) and what the subject of this email
// should be. It's a good idea to choose your own
// subject instead of allowing the user to. This will
// help prevent spam filters from snatching this email
// out from under your nose when something unusual is put.

$sendTo = "bob@hotmail.com";
$subject = "Stop Flushing site reply";

// variables are sent to this PHP page through
// the POST method. $_POST is a global associative array
// of variables passed through this method. From that, we
// can get the values sent to this page from Flash and
// assign them to appropriate variables which can be used
// in the PHP mail() function.


// header information not including sendTo and Subject
// these all go in one variable. First, include From:
$headers = "From: " . $_POST["firstName"] ." ". $_POST["lastname"] . "<" . $_POST["email"] .">\r\n";
// next include a replyto
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
// often email servers won't allow emails to be sent to
// domains other than their own. The return path here will
// often lift that restriction so, for instance, you could send
// email to a hotmail account. (hosting provider settings may vary)
// technically bounced email is supposed to go to the return-path email
$headers .= "Return-path: " . $_POST["email"];

// now we can add the content of the message to a body variable
$message = $_POST["company"] ." ". $_POST["address"] ." ". $_POST["phone"];


// once the variables have been defined, they can be included
// in the mail function call which will send you an email
mail($sendTo, $subject, $message, $headers);

?>

Ankou
November 18th, 2005, 06:37 PM
When makeing the message instead of the space between the company, address and phone you want to include two newlines. Typically you use '\r\n' -- of course I've had times when I had to just use '\n'.

So where you have :

$message = $_POST["company"] . " " . $_POST["address"] . " " . $_POST["phone"];

Try putting:

$message = $_POST["company"] . '\r\n\r\n'. $_POST["address"] . '\r\n\r\n'. $_POST["phone"];