My one question is that the From name is put together in my inbox. So if a user enters "User Name" and email "email@email.com", I get the following:
UserName email@email.com <subject>
The following is the code I am using:
Code: Select all
<?php
/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$recipient = 'me@gmail.com' ;
$subject = "FEEDBACK FROM T2H.COM" ;
$name = $HTTP_POST_VARS['name'];
$company = $HTTP_POST_VARS['company'];
$email = $HTTP_POST_VARS['email'];
$message = $HTTP_POST_VARS['message'];
// headers could be done in one line, but for clarity are separated
$mailheaders = "From: $name\r\n";
$mailheaders .= "Reply-To: $email\r\n";
$mailheaders .= "Return-Path: $email\r\n";
/* Makes message a bit neater */
$messageproper = "This message was sent from:\n" .
"Name: $name\n" .
"Email: $email\n" .
"Company: $company\n" .
"-----------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n" .
$message .
"\n\n-----------------------------------------------------------------------------------------------------------------------------------------------------------------\n" ;
/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<p>Invalid email address! Please go back and try again.</p>";
echo "<p><a href='javascript:history.back(1);'>Back</a></p>";
} elseif ($name == "") {
echo "<p>No name! Please go back and try again.</p>";
echo "<p><a href='javascript:history.back(1);'>Back</a></p>";
} elseif ($message == "") {
echo "<p>You didn't enter a message! Please go back and try again.</p>";
echo "<p><a href='javascript:history.back(1);'>Back</a></p>";
}
/* If no erros, Sends the mail and outputs the "Thank you" string */
else{
mail($recipient, $subject, $messageproper, $mailheaders);
echo "<p>Thanks for the feedback! If your message required a response, you can expect one within 24 hours.</p>";
}
?>This is going to sound completely naive, but I have became rather fascinated by PHP. I'm wondering what other most common uses there are for it? From small personal pages to Corporations, I'd like to know it's implementations.
I'm fairly familiar with C and C++ although it's been a while, so feel free to be somewhat in-depth ( ha, dont need var explained ).
Thanks, guys!
.t2h